From 940716fa2fa134a75d2ef34b41991c1c1c14735a Mon Sep 17 00:00:00 2001 From: Matthew Sotoudeh Date: Thu, 16 May 2024 11:35:02 -0700 Subject: make sure we don't allocate too-small blocks --- magic_buddy.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/magic_buddy.c b/magic_buddy.c index 1e88c21..868bfd7 100644 --- a/magic_buddy.c +++ b/magic_buddy.c @@ -86,7 +86,7 @@ static void *_allocate(size_t logsize, struct buddy *state) { return parent; } void *allocate(size_t size, struct buddy *state) { - size = (size < sizeof(struct free_block)) ? sizeof(struct free_block) : size; + if (size < sizeof(struct free_block)) size = sizeof(struct free_block); return _allocate(size2log(size, 1), state); } @@ -201,6 +201,8 @@ void *reallocate(void *old, size_t old_size, size_t new_size, struct buddy *state) { if (new_size == 0) return liberate(old, old_size, state), (void*)0; + if (size < sizeof(struct free_block)) size = sizeof(struct free_block); + size_t old_logsize = size2log(old_size, 1); size_t new_logsize = size2log(new_size, 1); -- cgit v1.2.3