* [PATCH] btrfs-progs: fix usage warning in common/help.c
@ 2024-10-11 4:17 Anand Jain
2024-10-11 4:39 ` Qu Wenruo
0 siblings, 1 reply; 2+ messages in thread
From: Anand Jain @ 2024-10-11 4:17 UTC (permalink / raw)
To: linux-btrfs
On systems with glibc 2.34 and 2.39, the following warning appears when
building the binary, causing concern that something has failed.
[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);
| ^~
The compiler warns that in some code paths, the token is `NULL`. Silence
the warning by checking if the token is `NULL`.
Signed-off-by: Anand Jain <anand.jain@oracle.com>
---
common/help.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/common/help.c b/common/help.c
index 6cf8e2a9b2ae..eff9aac537db 100644
--- a/common/help.c
+++ b/common/help.c
@@ -309,10 +309,11 @@ 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 ? token : "");
break;
case -2:
- fprintf(outf, "No short description for '%s'\n", token);
+ fprintf(outf, "No short description for '%s'\n",
+ token ? token : "");
break;
}
--
2.43.5
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] btrfs-progs: fix usage warning in common/help.c
2024-10-11 4:17 [PATCH] btrfs-progs: fix usage warning in common/help.c Anand Jain
@ 2024-10-11 4:39 ` Qu Wenruo
0 siblings, 0 replies; 2+ messages in thread
From: Qu Wenruo @ 2024-10-11 4:39 UTC (permalink / raw)
To: Anand Jain, linux-btrfs
在 2024/10/11 14:47, Anand Jain 写道:
> On systems with glibc 2.34 and 2.39, the following warning appears when
> building the binary, causing concern that something has failed.
>
> [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);
> | ^~
>
> The compiler warns that in some code paths, the token is `NULL`. Silence
> the warning by checking if the token is `NULL`.
>
> Signed-off-by: Anand Jain <anand.jain@oracle.com>
Reviewed-by: Qu Wenruo <wqu@suse.com>
Just a small improvement that I will do when merge.
> ---
> common/help.c | 5 +++--
> 1 file changed, 3 insertions(+), 2 deletions(-)
>
> diff --git a/common/help.c b/common/help.c
> index 6cf8e2a9b2ae..eff9aac537db 100644
> --- a/common/help.c
> +++ b/common/help.c
> @@ -309,10 +309,11 @@ 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 ? token : "");
You can just go with 'token ? : ""'
Thanks,
Qu
> break;
> case -2:
> - fprintf(outf, "No short description for '%s'\n", token);
> + fprintf(outf, "No short description for '%s'\n",
> + token ? token : "");
> break;
> }
>
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2024-10-11 4:39 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-10-11 4:17 [PATCH] btrfs-progs: fix usage warning in common/help.c Anand Jain
2024-10-11 4:39 ` Qu Wenruo
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox