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:39 -0800
commit06aefc8ac42726bd5038b2e0d75a0d88b53e263b (patch)
tree82138c6cdea5e1ece43b8259274fae49317deb51
parentf79271a4422e570109200fbf9e6424639cedbc01 (diff)
downloadcore-security-oc-mr1-release.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) {