From ca36e0dc35999d01467013b64e04d50f5ba4a417 Mon Sep 17 00:00:00 2001 From: Abdelrahman Said Date: Sun, 24 Mar 2024 17:24:33 +0000 Subject: [PATCH] Fix bug in the function that searches for the allocation header --- mem/src/arena/mem_arena.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/mem/src/arena/mem_arena.c b/mem/src/arena/mem_arena.c index a916ff3..decb484 100644 --- a/mem/src/arena/mem_arena.c +++ b/mem/src/arena/mem_arena.c @@ -337,7 +337,7 @@ internal ArenaAllocHDR *find_alloc_header(BaseArena *arena, void *alloc_ptr) { max_search_end > arena_buf_start ? max_search_end : arena_buf_start; bool match; - while (current > search_end) { + for (; current >= search_end; --current) { match = true; for (u64 i = 0; i < HDR_MAGIC_BYTE_COUNT; ++i) { @@ -350,9 +350,7 @@ internal ArenaAllocHDR *find_alloc_header(BaseArena *arena, void *alloc_ptr) { if (match) { return (ArenaAllocHDR *)current; } - - current -= HDR_MAGIC_BYTE_COUNT; - } + } return NULL; }