From 103277bf638a6d4265b8c074e64dabc3e9410ad5 Mon Sep 17 00:00:00 2001 From: karutoh Date: Thu, 8 Feb 2024 17:47:44 -0800 Subject: [PATCH] Added ralloc function. --- main.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/main.c b/main.c index 9510dc7..f88eb07 100644 --- a/main.c +++ b/main.c @@ -4,6 +4,7 @@ #define ALIGN4(s) (((((s)-1)>>2)<<2)+4) #define BLOCK_SIZE sizeof(struct block) +#define MINIMUM_BLOCK_SIZE 16 /// The memory block's header. struct block @@ -22,6 +23,10 @@ struct block* last = NULL; /// @returns The new memory block. struct block* extend_heap(size_t s) { + // Ensure the allocated size is at least the minimum block size + if (s < MINIMUM_BLOCK_SIZE) + s = MINIMUM_BLOCK_SIZE; + struct block* b = sbrk(0); if (sbrk(BLOCK_SIZE + s) == (void*)-1)