diff options
author | quou <quou@disroot.org> | 2023-05-25 07:43:47 +1000 |
---|---|---|
committer | quou <quou@disroot.org> | 2023-05-25 07:43:47 +1000 |
commit | 5b27950ef80d36d9b8e2257990aa50932c05b04d (patch) | |
tree | bdcd223cc87a22fda79d858ffb39a7aff41e6cfc | |
parent | 978ab7ede2bbf0decc5913f0707a0632e9ae4ff2 (diff) |
Update the heap allocator.
-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); |