From d44cc5dd91e86fd5d865ece585f2e151d44d6689 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Tue, 18 Jul 2017 17:46:12 +0200 Subject: [PATCH 1/2] xdu: Make format string a string lateral 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", ``` --- xdu.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/xdu.c b/xdu.c index 3c21373..dd0d37c 100644 --- a/xdu.c +++ b/xdu.c @@ -215,7 +215,7 @@ char **argv; xsetup(&argc, argv); if (argc == 1) { if (isatty(fileno(stdin))) { - fprintf(stderr, usage); + fprintf(stderr, "%s", usage); exit(1); } else { parse_file("-"); @@ -223,7 +223,7 @@ char **argv; } else if (argc == 2 && strcmp(argv[1], "-help") != 0) { parse_file(argv[1]); } else { - fprintf(stderr, usage); + fprintf(stderr, "%s", usage); exit(1); } top.size = fix_tree(&top); From efa72d70220b751a63d1f84f38e4c7c6371e2979 Mon Sep 17 00:00:00 2001 From: Paul Menzel Date: Tue, 18 Jul 2017 17:52:12 +0200 Subject: [PATCH 2/2] xdu: Initialize variables `name` in all cases 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. --- xdu.c | 1 + 1 file changed, 1 insertion(+) diff --git a/xdu.c b/xdu.c index dd0d37c..747ce68 100644 --- a/xdu.c +++ b/xdu.c @@ -885,6 +885,7 @@ void savepsnode(FILE * fp, struct node *nodep, struct rect rect, int showsize) name = label; break; default: + name = NULL; break; }