diff options
-rw-r--r-- | heap.c | 5 |
1 files changed, 3 insertions, 2 deletions
@@ -82,10 +82,11 @@ static uintptr_t align_address( } static void* heap_alloc_impl(Heap* h, int size) { - int* header, * nh, s, f, i, as, p; + int* header, * nh, s, f, i, as, p, m; i = 0; as = size + sizeof *header; p = 0; + m = sizeof *header - 1; for (i = 0; i < h->blocks; i++) { header = (int*)(h->buffer + p); s = header[0]; @@ -94,7 +95,7 @@ static void* heap_alloc_impl(Heap* h, int size) { if (f) { /* There's no point creating blocks smaller than * the header. */ - if (as < s - sizeof *header - 1) { + if (as < s - m) { s -= as; header[0] = (s << 1); nh = (int*)(h->buffer + p + s); |