From 3bbef7348b5127406af64a69eae33cff4c3eb818 Mon Sep 17 00:00:00 2001 From: llucinat Date: Thu, 5 Sep 2019 15:07:02 +0200 Subject: [PATCH] Fix heap initialization --- tinyalloc.c | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/tinyalloc.c b/tinyalloc.c index 5d2e82d..eb9fa3f 100644 --- a/tinyalloc.c +++ b/tinyalloc.c @@ -22,7 +22,6 @@ typedef struct { Block *used; // first used block Block *fresh; // first available blank block size_t top; // top free addr - Block *blocks; } Heap; static Heap *heap = NULL; @@ -121,11 +120,10 @@ bool ta_init(const void *base, const void *limit, const size_t heap_blocks, cons heap->free = NULL; heap->used = NULL; - heap->fresh = heap->blocks; - heap->top = (size_t)base + sizeof(Heap) + heap_blocks * sizeof(Block); - heap->blocks = (Block*) (base + sizeof(Heap)); + heap->fresh = (Block *)(heap + 1); + heap->top = (size_t)(heap->fresh + heap_blocks); - Block *block = heap->blocks; + Block *block = heap->fresh; size_t i = heap_max_blocks - 1; while (i--) { block->next = block + 1;