From f907461b9024e8b7a00706d4cfc6fe50973547e2 Mon Sep 17 00:00:00 2001 From: Laria Carolin Chabowski Date: Wed, 15 Dec 2021 21:24:21 +0100 Subject: [PATCH] resizable: Fix capacity growing --- src/resizable.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/resizable.c b/src/resizable.c index fd86133..895f80a 100644 --- a/src/resizable.c +++ b/src/resizable.c @@ -42,12 +42,12 @@ apfl_resizable_grow_cap(size_t elem_size, void **mem, size_t *len, size_t *cap, return true; } - size_t newcap = *cap + elem_size * inc_cap; + size_t newcap = *cap + inc_cap; // TODO: We currently simply grow the memory to have space for exactly // inc_cap more elements. It would probably be smarter to grow the // memory a bit larger to reduce calls to realloc. - void *newmem = realloc(*mem, newcap); + void *newmem = realloc(*mem, newcap * elem_size); if (newmem == NULL) { return false; }