src/array_list.c

changeset 627
cc8cbabd27cd
parent 626
254cc61c71a0
child 628
1e2be40f0cb5
equal deleted inserted replaced
626:254cc61c71a0 627:cc8cbabd27cd
50 50
51 /* determine capacity */ 51 /* determine capacity */
52 size_t cap = capacity == NULL ? *size : *capacity; 52 size_t cap = capacity == NULL ? *size : *capacity;
53 53
54 /* check if resize is required */ 54 /* check if resize is required */
55 size_t newsize = index + elem_count; 55 size_t minsize = index + elem_count;
56 size_t newsize = *size < minsize ? minsize : *size;
56 bool needrealloc = newsize > cap; 57 bool needrealloc = newsize > cap;
57 58
58 /* reallocate if possible */ 59 /* reallocate if possible */
59 if (needrealloc) { 60 if (needrealloc) {
60 /* a reallocator and a capacity variable must be available */ 61 /* a reallocator and a capacity variable must be available */

mercurial