diff options
author | Steven Moreland <smoreland@google.com> | 2019-11-06 16:06:57 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-11-06 16:06:57 -0800 |
commit | 3f273f49f1d9274b1637676c336d031f3a85646e (patch) | |
tree | 82138c6cdea5e1ece43b8259274fae49317deb51 | |
parent | ca662c71185e94bfe43a3a0c73cd78f6113fc98e (diff) | |
parent | 59e7d4e8ea46ec4adf0dbe0fc9f801db98f1d5c6 (diff) | |
download | core-3f273f49f1d9274b1637676c336d031f3a85646e.tar.gz |
FlattenableUtils::align memsets am: e62a9d7669
am: 59e7d4e8ea
Change-Id: I1105027b52c3621e2031bdb747de61ce54d3ec74
-rw-r--r-- | libutils/include/utils/Flattenable.h | 7 |
1 files changed, 6 insertions, 1 deletions
diff --git a/libutils/include/utils/Flattenable.h b/libutils/include/utils/Flattenable.h index 070c71026..0f9d259cb 100644 --- a/libutils/include/utils/Flattenable.h +++ b/libutils/include/utils/Flattenable.h @@ -47,7 +47,12 @@ public: template<size_t N> static size_t align(void*& buffer) { - return align<N>( const_cast<void const*&>(buffer) ); + static_assert(!(N & (N - 1)), "Can only align to a power of 2."); + void* b = buffer; + buffer = reinterpret_cast<void*>((uintptr_t(buffer) + (N-1)) & ~(N-1)); + size_t delta = size_t(uintptr_t(buffer) - uintptr_t(b)); + memset(b, 0, delta); + return delta; } static void advance(void*& buffer, size_t& size, size_t offset) { |