summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-11-06 16:32:08 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-06 16:32:08 -0800
commit81303e4c8f3889857925d4253a8a134d088a13a0 (patch)
tree3009c6e673e423dcc11109897f7f26c11ce8c966
parentaebebeb92311f9867200238835eb0aced259a8b7 (diff)
parent80965d4ee9447fd3133a7f160638f7e0940e193e (diff)
downloadcore-81303e4c8f3889857925d4253a8a134d088a13a0.tar.gz
FlattenableUtils::align memsets am: e62a9d7669 am: 59e7d4e8ea am: 3f273f49f1 am: f7724dfcfb am: 4392bca7f7
am: 80965d4ee9 Change-Id: Ic58551fdd717a31b71831dfe1c39a970700edf7c
-rw-r--r--libutils/include/utils/Flattenable.h7
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) {