These two warnings unistr/test-u-strtok.h:54:28: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size] unistr/test-u-strtok.h:56:28: warning: allocated buffer size is not a multiple of the pointee's size [CWE-131] [-Wanalyzer-allocation-size]
point to a real problem: confusion between 'UNIT *' and 'char *'. Fixed like this: 2023-09-04 Bruno Haible <br...@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. diff --git a/tests/unistr/test-u-strtok.h b/tests/unistr/test-u-strtok.h index a156d58d24..c7da3d4027 100644 --- a/tests/unistr/test-u-strtok.h +++ b/tests/unistr/test-u-strtok.h @@ -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;