Skip to content

Commit

Permalink
btrfs-progs: fix usage warning in common/help.c
Browse files Browse the repository at this point in the history
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`.

Reviewed-by: Qu Wenruo <[email protected]>
Signed-off-by: Anand Jain <[email protected]>
  • Loading branch information
asj authored and adam900710 committed Oct 11, 2024
1 parent bb1e846 commit b25146b
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions common/help.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit b25146b

Please sign in to comment.