]> Savannah Git Hosting - gnulib.git/commitdiff
unistr/u{8,16,32}-strtok tests: Fix -Wanalyzer-allocation-size warnings.
authorBruno Haible <bruno@clisp.org>
Tue, 5 Sep 2023 01:06:30 +0000 (03:06 +0200)
committerBruno Haible <bruno@clisp.org>
Thu, 14 Sep 2023 10:14:01 +0000 (12:14 +0200)
* tests/unistr/test-u-strtok.h (test_u_strtok): Correct values of
input_len and delim_len.

ChangeLog
tests/unistr/test-u-strtok.h

index 6e4ba532aec157aad02aa96fa30a05b7610bef05..9c3eca693c9303de14ecb216bccaf109a0697df5 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,9 @@
 2023-09-04  Bruno Haible  <bruno@clisp.org>
 
+       unistr/u{8,16,32}-strtok tests: Fix -Wanalyzer-allocation-size warnings.
+       * tests/unistr/test-u-strtok.h (test_u_strtok): Correct values of
+       input_len and delim_len.
+
        sigpipe tests: Fix -Wanalyzer-unsafe-call-within-signal-handler warning.
        * tests/test-sigpipe.c (handler): Invoke _exit, not exit.
        * tests/test-raise.c (handler): Update comments after 2020-11-25 change.
index a156d58d249a98f2d64fe4eaa75fe92fe2444d72..c7da3d4027821bc7a70fa91e610d9542c68a7c20 100644 (file)
@@ -50,10 +50,12 @@ test_u_strtok (void)
         'A', 'B', 'C', 'D', 'A', 'B', 'C', 'D', 'A', 'B', 'D', 'E', 0
       };
     ucs4_t u_delim[] = { 0x3000, 0x3001, 0 };
-    size_t input_len = 6 * SIZEOF (u_input);
-    UNIT *input = (UNIT *) malloc (input_len);
-    size_t delim_len = 6 * SIZEOF (u_delim);
-    UNIT *delim = (UNIT *) malloc (delim_len);
+    /* Convert ucs4_t[] to UNIT[].
+       Every ucs4_t yields at most 4 / sizeof (UNIT) units.  */
+    size_t input_len = SIZEOF (u_input) * (4 / sizeof (UNIT));
+    UNIT *input = (UNIT *) malloc (input_len * sizeof (UNIT));
+    size_t delim_len = SIZEOF (u_delim) * (4 / sizeof (UNIT));
+    UNIT *delim = (UNIT *) malloc (delim_len * sizeof (UNIT));
     UNIT *state;
     const UNIT *result;
     UNIT *ptr, *first_ptr, *second_ptr;