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>
This commit is contained in:
Simon McVittie
2022-10-10 15:35:11 +01:00
parent 8f2e676d9b
commit 416744a265

View File

@@ -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))