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
     1.1 --- a/src/array_list.c	Sun Nov 20 17:06:00 2022 +0100
     1.2 +++ b/src/array_list.c	Sun Nov 20 17:22:37 2022 +0100
     1.3 @@ -68,8 +68,9 @@
     1.4          bool repairsrc = targetaddr <= srcaddr
     1.5                           && srcaddr < targetaddr + cap * elem_size;
     1.6  
     1.7 -        /* increase capacity linearly */
     1.8 -        cap += 16;
     1.9 +        /* calculate new capacity (next number divisible by 16) */
    1.10 +        cap = newsize - (newsize % 16) + 16;
    1.11 +        assert(cap > newsize);
    1.12  
    1.13          /* perform reallocation */
    1.14          void *newmem = reallocator->realloc(

mercurial