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)