1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-07-27 04:57:45 +00:00

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.
This commit is contained in:
Idan Horowitz 2021-04-28 16:43:25 +03:00 committed by Linus Groh
parent ae5ee2220c
commit edfe81b1ee

View file

@ -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;