[libglnx/wip/smcv/strtok-r] tests: Ensure saveptr is NULL before first call to strtok_r()




commit 416744a26533b7beabb32b0af3042ea32f808d0d
Author: Simon McVittie <smcv collabora com>
Date:   Mon Oct 10 15:35:11 2022 +0100

    tests: Ensure saveptr is NULL before first call to strtok_r()
    
    The standards-conformant behaviour is that the contents of saveptr
    are ignored when the first argument is non-NULL, but the man page notes
    that some older implementations required saveptr to be NULL in that
    situation, and the gcc 4.8 provided by the Steam Runtime warns about this.
    
    Signed-off-by: Simon McVittie <smcv collabora com>

 tests/test-libglnx-testing.c | 12 +++++++++---
 1 file changed, 9 insertions(+), 3 deletions(-)
---
diff --git a/tests/test-libglnx-testing.c b/tests/test-libglnx-testing.c
index 279e0e1..8435113 100644
--- a/tests/test-libglnx-testing.c
+++ b/tests/test-libglnx-testing.c
@@ -171,7 +171,7 @@ test_failures (void)
       int wait_status = -1;
       const char *argv[] = { NULL, NULL, NULL, NULL };
       char *line;
-      char *saveptr;
+      char *saveptr = NULL;
 
       argv[0] = exe;
       argv[1] = failures[i];
@@ -195,6 +195,8 @@ test_failures (void)
            line = strtok_r (NULL, "\n", &saveptr))
         g_test_message ("stdout: %s", line);
 
+      saveptr = NULL;
+
       for (line = strtok_r (err, "\n", &saveptr);
            line != NULL;
            line = strtok_r (NULL, "\n", &saveptr))
@@ -241,7 +243,7 @@ test_skips (void)
       int wait_status = -1;
       const char *argv[] = { NULL, NULL, NULL, NULL };
       char *line;
-      char *saveptr;
+      char *saveptr = NULL;
 
       argv[0] = exe;
       argv[1] = skips[i];
@@ -265,6 +267,8 @@ test_skips (void)
            line = strtok_r (NULL, "\n", &saveptr))
         g_test_message ("stdout: %s", line);
 
+      saveptr = NULL;
+
       for (line = strtok_r (err, "\n", &saveptr);
            line != NULL;
            line = strtok_r (NULL, "\n", &saveptr))
@@ -311,7 +315,7 @@ test_successes (void)
       int wait_status = -1;
       const char *argv[] = { NULL, NULL, NULL, NULL };
       char *line;
-      char *saveptr;
+      char *saveptr = NULL;
 
       argv[0] = exe;
       argv[1] = successes[i];
@@ -335,6 +339,8 @@ test_successes (void)
            line = strtok_r (NULL, "\n", &saveptr))
         g_test_message ("stdout: %s", line);
 
+      saveptr = NULL;
+
       for (line = strtok_r (err, "\n", &saveptr);
            line != NULL;
            line = strtok_r (NULL, "\n", &saveptr))


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]