aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorXavier Del Campo Romero <xavi92@disroot.org>2025-11-12 00:37:51 +0100
committerXavier Del Campo Romero <xavi92@disroot.org>2025-11-12 00:37:51 +0100
commit07bff5530cf22d95b98139063ab50cabb8cabe76 (patch)
tree4c91a123b98cba9b0f44ddb6f97a7add22592369
parentfd8128d9b84e362abdbd05fafe252421edee8ab2 (diff)
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.
-rw-r--r--tinyalloc.c5
1 files changed, 0 insertions, 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;