aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorquou <quou@disroot.org>2023-05-25 07:43:47 +1000
committerquou <quou@disroot.org>2023-05-25 07:43:47 +1000
commit5b27950ef80d36d9b8e2257990aa50932c05b04d (patch)
treebdcd223cc87a22fda79d858ffb39a7aff41e6cfc
parent978ab7ede2bbf0decc5913f0707a0632e9ae4ff2 (diff)
Update the heap allocator.
-rw-r--r--heap.c5
1 files 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);