fix cx_array_copy() unintentionally shrinking the array

Sun, 20 Nov 2022 17:48:42 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 20 Nov 2022 17:48:42 +0100
changeset 627
cc8cbabd27cd
parent 626
254cc61c71a0
child 628
1e2be40f0cb5

fix cx_array_copy() unintentionally shrinking the array

src/array_list.c file | annotate | diff | comparison | revisions
--- 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 */

mercurial