From d6d4f2a0d9fa5699d613379136cf318635ed6091 Mon Sep 17 00:00:00 2001 From: jackjohn7 <70782491+jackjohn7@users.noreply.github.com> Date: Mon, 15 Jun 2026 22:35:03 -0500 Subject: [PATCH] feat: bounds check, refactor --- src/jalloc.c | 18 +++++++++++++----- 1 file changed, 13 insertions(+), 5 deletions(-) diff --git a/src/jalloc.c b/src/jalloc.c index 7508b0e..4bd6120 100644 --- a/src/jalloc.c +++ b/src/jalloc.c @@ -2,13 +2,21 @@ #include #include -#define HEAP_SIZE (1024 * 1024) +#define HEAP_SIZE (1024 * 1024 * 2) +#define ALIGNMENT 8 static uint8_t heap[HEAP_SIZE]; -static size_t heap_offset = 0; +static uint8_t *heap_ptr = heap; -void* jalloc(size_t size) { - void* ptr = &heap[heap_offset]; - heap_offset += size; +/** + * Allocate memory via bump allocation + */ +void *jalloc(size_t size) { + if (heap_ptr + size > heap + sizeof(heap)) return NULL; + + void *ptr = heap_ptr; + heap_ptr += size; return ptr; } + +void jfree(void *ptr) {}