resizable: Fix capacity growing

This commit is contained in:
Laria 2021-12-15 21:24:21 +01:00
parent 09d51b9080
commit f907461b90

View file

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