From 07bff5530cf22d95b98139063ab50cabb8cabe76 Mon Sep 17 00:00:00 2001 From: Xavier Del Campo Romero Date: Wed, 12 Nov 2025 00:37:51 +0100 Subject: Do not resize blocks on realloc This allocator was not designed for reallocations, and therefore prev->size cannot be extended because that would overlap its contents with other data. Because of this, the only safe way to achieve a reallocation is to always allocate a new block, copy any existing data and free the old block. --- tinyalloc.c | 5 ----- 1 file changed, 5 deletions(-) diff --git a/tinyalloc.c b/tinyalloc.c index 69eaeb5..1c53567 100644 --- a/tinyalloc.c +++ b/tinyalloc.c @@ -280,11 +280,6 @@ void *ta_realloc(void *ptr, size_t n) { if (!ptr) return NULL; - else if (n <= prev->size) - { - prev->size = n; - return prev->addr; - } char *const new = ta_alloc(n), *p = new; const char *src = prev->addr; -- cgit v1.2.3