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 */ |