Sun, 20 Nov 2022 17:22:37 +0100
fix calculation of new capacity in cx_array_copy()
src/array_list.c | file | annotate | diff | comparison | revisions |
--- a/src/array_list.c Sun Nov 20 17:06:00 2022 +0100 +++ b/src/array_list.c Sun Nov 20 17:22:37 2022 +0100 @@ -68,8 +68,9 @@ bool repairsrc = targetaddr <= srcaddr && srcaddr < targetaddr + cap * elem_size; - /* increase capacity linearly */ - cap += 16; + /* calculate new capacity (next number divisible by 16) */ + cap = newsize - (newsize % 16) + 16; + assert(cap > newsize); /* perform reallocation */ void *newmem = reallocator->realloc(