[kutil] Fix a bug with order ignoring header size

When moving heap allocation order calculation to use __builtin_clz, we
based that calculation off of the length requested, not the totla length
including the memory header size.
This commit is contained in:
2020-08-02 16:54:06 -07:00
parent 94c1f0d3fc
commit 911b4c0b10

View File

@@ -77,7 +77,9 @@ heap_allocator::allocate(size_t length)
if (length == 0) if (length == 0)
return nullptr; return nullptr;
unsigned order = 64 - __builtin_clz(length); const unsigned clz = __builtin_clzll(total);
const unsigned order = 64 - clz;
kassert(order <= max_order, "Tried to allocate a block bigger than max_order"); kassert(order <= max_order, "Tried to allocate a block bigger than max_order");
if (order > max_order) if (order > max_order)
return nullptr; return nullptr;