From dbabafa3edf9e18533a4860594f97356853975c2 Mon Sep 17 00:00:00 2001 From: Anand Jain Date: Fri, 11 Oct 2024 12:17:19 +0800 Subject: [PATCH] btrfs-progs: fix usage warning in common/help.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit On systems with glibc 2.34 and 2.39, the following warning appears when building the binary: [CC] common/help.o common/help.c: In function ‘usage’: common/help.c:315:58: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 315 | fprintf(outf, "No short description for '%s'\n", token); | ^~ common/help.c:312:46: warning: ‘%s’ directive argument is null [-Wformat-overflow=] 312 | fprintf(outf, "No usage for '%s'\n", token); | ^~ This happens for usage() which passes NULL pointer as token. Normally this is fine, as fprintf() will output "(null)" for the NULL pointer, but it's still not ideal. Fix the warning by changing the token to "" if it's NULL. Reviewed-by: Qu Wenruo Signed-off-by: Anand Jain --- common/help.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/common/help.c b/common/help.c index 6cf8e2a9b2..0ee00a3a13 100644 --- a/common/help.c +++ b/common/help.c @@ -309,10 +309,10 @@ static int usage_command_internal(const char * const *usagestr, ret = do_usage_one_command(usagestr, flags, cmd_flags, outf); switch (ret) { case -1: - fprintf(outf, "No usage for '%s'\n", token); + fprintf(outf, "No usage for '%s'\n", token ? : ""); break; case -2: - fprintf(outf, "No short description for '%s'\n", token); + fprintf(outf, "No short description for '%s'\n", token ? : ""); break; }