Skip to content

Commit

Permalink
tests/sw_tree1.c: fix unitialized saveptr
Browse files Browse the repository at this point in the history
Building the dtc tests on the Conda build system results in the
following error.

> In function '__strtok_r_1c',                                                                                                                                     2024-11-23T19:17:20.7930512Z     inlined from 'main' at ../tests/sw_tree1.c:140:17:
> $BUILD_PREFIX/x86_64-conda-linux-gnu/sysroot/usr/include/bits/string2.h:1177:10: error: 'saveptr' may be used uninitialized [-Werror=maybe-uninitialized]
>  1177 |   while (*__s == __sep)
>       |          ^~~~
> ../tests/sw_tree1.c: In function 'main':
> ../tests/sw_tree1.c:137:39: note: 'saveptr' was declared here
>   137 |                 char *str = argv[2], *saveptr, *tok;
>       |                                       ^~~~~~~
> cc1: all warnings being treated as errors

The manpage `strtok(3)` says the following.

> VERSIONS
>   On some implementations, *saveptr is required to be NULL on the first call to strtok_r() that is being used to parse str.

So set it to NULL.

Signed-off-by: Brandon Maier <[email protected]>
  • Loading branch information
blmaier authored and dgibson committed Nov 25, 2024
1 parent 9a969f3 commit 66c7d0e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion tests/sw_tree1.c
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ int main(int argc, char *argv[])
}
}
if (argc == 3) {
char *str = argv[2], *saveptr, *tok;
char *str = argv[2], *saveptr = NULL, *tok;
bool default_flag = false;

while ((tok = strtok_r(str, ",", &saveptr)) != NULL) {
Expand Down

0 comments on commit 66c7d0e

Please sign in to comment.