summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Sotoudeh <matthew@masot.net>2024-05-16 11:35:02 -0700
committerMatthew Sotoudeh <matthew@masot.net>2024-05-16 11:35:02 -0700
commit940716fa2fa134a75d2ef34b41991c1c1c14735a (patch)
treedef028588949c76c008bcd232e68a0744da8f55e
parent964fea7500f4bcba3bf2629e959df415ee0ce48f (diff)
make sure we don't allocate too-small blocks
-rw-r--r--magic_buddy.c4
1 files changed, 3 insertions, 1 deletions
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);
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback