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; }