summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSteven Moreland <smoreland@google.com>2019-10-07 17:31:17 -0700
committerKyriakos Ispoglou <ispo@google.com>2019-11-07 16:19:49 -0800
commit6129c4b91cb9f24b8a754f1b2d22a869ebebe5b4 (patch)
tree6834e7226b5064340c3f16b9a191432e80b12258
parent80de9f33616bb8d5b740ea86b05345bc7e274561 (diff)
downloadcore-android-8.0.0_r50.tar.gz
Bug: 141890807 Test: boot, check data is zero'd Change-Id: I45aaeac369f4c5cf3eb44f61c233e00f870a5c79 (cherry picked from commit bf824f8fa50d9f7390057278fefb58e83323a644) (cherry picked from commit e62a9d7669ac85844d4424474f5c88c096f7160b)
-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 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) {