diff options
author | Steven Moreland <smoreland@google.com> | 2019-11-06 16:26:06 -0800 |
---|---|---|
committer | android-build-merger <android-build-merger@google.com> | 2019-11-06 16:26:06 -0800 |
commit | 80965d4ee9447fd3133a7f160638f7e0940e193e (patch) | |
tree | 2e00a4f384ecf6640c79e89477aed16ab94d2a9f | |
parent | 92fa5730de3b3ef185721c03f5037db9a3d84366 (diff) | |
parent | 4392bca7f7e9c329fdd240b927f6d6297d3931d1 (diff) | |
download | core-80965d4ee9447fd3133a7f160638f7e0940e193e.tar.gz |
FlattenableUtils::align memsets am: e62a9d7669 am: 59e7d4e8ea am: 3f273f49f1 am: f7724dfcfb
am: 4392bca7f7
Change-Id: I0d51ef04b0641889117054cc36499acdbac83220
-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 9d006023d..2c4b8075d 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) { |