gcc 13 produces this warning:

test-argv-iter.c:97:35: warning: buffer under-read [CWE-127] 
[-Wanalyzer-out-of-bounds]

It's not really a buffer under-read. But the test's logic is complicated
enough that it took me two minutes to understand why it's a false positive.
The test can be simplified accordingly, making it more maintainable.


2023-09-04  Bruno Haible  <br...@clisp.org>

        argv-iter tests: Avoid gcc -Wanalyzer-out-of-bounds warning.
        * tests/test-argv-iter.c (main): Simplify logic.

diff --git a/tests/test-argv-iter.c b/tests/test-argv-iter.c
index ea5803ab46..8d97da9146 100644
--- a/tests/test-argv-iter.c
+++ b/tests/test-argv-iter.c
@@ -86,15 +86,14 @@ main (void)
               ASSERT ((i == n_found) == (ai_err == AI_ERR_EOF));
               ASSERT ((s == NULL) ^ (ai_err == AI_ERR_OK));
               ASSERT (ai_err == AI_ERR_OK || ai_err == AI_ERR_EOF);
-              if (ai_err == AI_ERR_OK)
-                ++n_found;
               if (ai_err == AI_ERR_EOF)
                 break;
               /* In stream mode, the strings are equal, but
                  in argv mode the actual pointers are equal.  */
               ASSERT (use_stream
-                      ? STREQ (s, av[i][n_found - 1])
-                      : s == av[i][n_found - 1]);
+                      ? STREQ (s, av[i][n_found])
+                      : s == av[i][n_found]);
+              ++n_found;
             }
           ASSERT (argv_iter_n_args (ai) == i);
           argv_iter_free (ai);




Reply via email to