summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-11-06 16:19:08 -0800
committerandroid-build-merger <android-build-merger@google.com>2019-11-06 16:19:08 -0800
commit4392bca7f7e9c329fdd240b927f6d6297d3931d1 (patch)
treed93e12fa5998c60bb7626ecfde2392597529438a
parent184e9461c5fe5cf7924527584db2c526034ee5ad (diff)
parentf7724dfcfb2af2ee2c50e116c8a1784b0eceab21 (diff)
downloadcore-4392bca7f7e9c329fdd240b927f6d6297d3931d1.tar.gz
FlattenableUtils::align memsets am: e62a9d7669 am: 59e7d4e8ea am: 3f273f49f1
am: f7724dfcfb Change-Id: I0ecdb9a58418d0c65629c70fc6df2a4aad7a1784
-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) {