Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tests/sw_tree1.c: fix unitialized saveptr #158

Merged
merged 1 commit into from
Nov 25, 2024

Conversation

blmaier
Copy link
Contributor

@blmaier blmaier commented Nov 23, 2024

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.

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]>
@blmaier blmaier force-pushed the fix-sw_tree1-strtok_r branch from 42b2112 to bfdafea Compare November 25, 2024 01:54
@dgibson dgibson merged commit 66c7d0e into dgibson:main Nov 25, 2024
12 checks passed
@blmaier blmaier deleted the fix-sw_tree1-strtok_r branch November 25, 2024 02:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants