fix assertion failure depending on possibly uninitialized memory

Tue, 16 Jan 2024 23:12:43 +0100

author
Mike Becker <universe@uap-core.de>
date
Tue, 16 Jan 2024 23:12:43 +0100
changeset 809
b7e2e1d7ed22
parent 808
f7f193893894
child 810
85859399a0cc

fix assertion failure depending on possibly uninitialized memory

tests/test_string.c file | annotate | diff | comparison | revisions
--- a/tests/test_string.c	Tue Jan 16 21:34:21 2024 +0100
+++ b/tests/test_string.c	Tue Jan 16 23:12:43 2024 +0100
@@ -179,8 +179,11 @@
     size_t const longstrpatternlen = 64 + cx_strstr_sbo_size;
     size_t const longstrlen = 320 + longstrpatternlen + 14;
 
-    char *longstrc = malloc(longstrlen+1);
-    char *longstrpatternc = malloc(longstrpatternlen+1);
+    // it is more expensive to use calloc here, because we will overwrite
+    // the memory anyway in the test preparation - but it is more reliable
+    // in case we are doing something horribly wrong
+    char *longstrc = calloc(longstrlen+1, 1);
+    char *longstrpatternc = calloc(longstrpatternlen+1, 1);
 
     memcpy(longstrc,
            "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghijkl"

mercurial