From edfe81b1ee2141a6b543001cdfbfc330a2f1338f Mon Sep 17 00:00:00 2001 From: Idan Horowitz Date: Wed, 28 Apr 2021 16:43:25 +0300 Subject: [PATCH] LibC: static_assert that all malloc size classes have an alignment of 8 This will help prevent issues like the one fixed by #6703 from happening again. --- Userland/Libraries/LibC/mallocdefs.h | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/Userland/Libraries/LibC/mallocdefs.h b/Userland/Libraries/LibC/mallocdefs.h index 4b226e7b0f..71223b2822 100644 --- a/Userland/Libraries/LibC/mallocdefs.h +++ b/Userland/Libraries/LibC/mallocdefs.h @@ -17,6 +17,16 @@ static constexpr unsigned short size_classes[] = { 8, 16, 32, 64, 128, 256, 504, 1016, 2032, 4088, 8184, 16376, 32752, 0 }; static constexpr size_t num_size_classes = (sizeof(size_classes) / sizeof(unsigned short)) - 1; +consteval bool check_size_classes_alignment() +{ + for (size_t i = 0; i < num_size_classes; i++) { + if ((size_classes[i] % 8) != 0) + return false; + } + return true; +} +static_assert(check_size_classes_alignment()); + struct CommonHeader { size_t m_magic; size_t m_size;