diff --git a/libutils/include/utils/Flattenable.h b/libutils/include/utils/Flattenable.h index 953b85988..17c5e1057 100644 --- a/libutils/include/utils/Flattenable.h +++ b/libutils/include/utils/Flattenable.h @@ -52,7 +52,12 @@ public: template static size_t align(void*& buffer) { - return align( const_cast(buffer) ); + static_assert(!(N & (N - 1)), "Can only align to a power of 2."); + void* b = buffer; + buffer = reinterpret_cast((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) {