From 5b27950ef80d36d9b8e2257990aa50932c05b04d Mon Sep 17 00:00:00 2001 From: quou Date: Thu, 25 May 2023 07:43:47 +1000 Subject: Update the heap allocator. --- heap.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/heap.c b/heap.c index 586bdfc..3f4fb91 100644 --- a/heap.c +++ b/heap.c @@ -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); -- cgit v1.2.3-54-g00ecf