Skip to content

Fix Clang warnings #5

Merged
merged 2 commits into from Jul 18, 2017
Merged

Fix Clang warnings #5

merged 2 commits into from Jul 18, 2017

Conversation

pmenzel
Copy link
Contributor

@pmenzel pmenzel commented Jul 18, 2017

Slightly change the code to make Clang happy.

$ clang --version
clang version 4.0.0 (tags/RELEASE_400/final)
Target: x86_64-unknown-linux-gnu
Thread model: posix
InstalledDir: /usr/bin
$ make CC=clang
clang -Wall -Werror -Wextra -pedantic -std=gnu99   -c -o xdu.o xdu.c
clang -Wall -Werror -Wextra -pedantic -std=gnu99   -c -o xwin.o xwin.c
clang -o xdu xdu.o xwin.o -lm -lXaw -lXt -lX11

Clang 4.0.0 shows the warnings below.

```
$ CC=clang make
clang -Wall -Werror -Wextra -pedantic -std=gnu99   -c -o xdu.o xdu.c
xdu.c:218:29: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
            fprintf(stderr, usage);
                            ^~~~~
xdu.c:218:29: note: treat the string as an argument to avoid this
            fprintf(stderr, usage);
                            ^
                            "%s",
xdu.c:226:25: error: format string is not a string literal (potentially insecure) [-Werror,-Wformat-security]
        fprintf(stderr, usage);
                        ^~~~~
xdu.c:226:25: note: treat the string as an argument to avoid this
        fprintf(stderr, usage);
                        ^
                        "%s",
```
Clang 4.0.0 warns about the use of a possibly uninitialized variable.

```
$ CC=clang make
clang -Wall -Werror -Wextra -pedantic -std=gnu99   -c -o xdu.o xdu.c
xdu.c:887:5: error: variable 'name' is used uninitialized whenever switch default is taken [-Werror,-Wsometimes-uninitialized]
    default:
    ^~~~~~~
xdu.c:892:78: note: uninitialized use occurs here
    fprintpstext(fp, rect.left + 4, rect.top + (rect.height - rect.top) / 2, name);
                                                                             ^~~~
xdu.c:868:28: note: initialize the variable 'name' to silence this warning
    char label[1024], *name;
                           ^
                            = NULL
1 error generated.
```

Only the function `a_saveps()` is the caller of that path, and passes
`res.showsize()`. Maybe that parameter should be checked by the caller
and an assert be added.

Setting the variable to NULl fixes the issue.
@wwwutz wwwutz merged commit 04fbcb9 into master Jul 18, 2017
@wwwutz
Copy link
Contributor

wwwutz commented Jul 18, 2017

Thanks!

Sign in to join this conversation on GitHub.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants