fix calculation of new capacity in cx_array_copy()

Sun, 20 Nov 2022 17:22:37 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 20 Nov 2022 17:22:37 +0100
changeset 625
a4c4a50c067a
parent 624
b0bdff7d8203
child 626
254cc61c71a0

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(

mercurial