diff -r 254cc61c71a0 -r cc8cbabd27cd src/array_list.c --- a/src/array_list.c Sun Nov 20 17:47:26 2022 +0100 +++ b/src/array_list.c Sun Nov 20 17:48:42 2022 +0100 @@ -52,7 +52,8 @@ size_t cap = capacity == NULL ? *size : *capacity; /* check if resize is required */ - size_t newsize = index + elem_count; + size_t minsize = index + elem_count; + size_t newsize = *size < minsize ? minsize : *size; bool needrealloc = newsize > cap; /* reallocate if possible */