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:

    [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 <[email protected]>
Signed-off-by: Anand Jain <[email protected]>
  • Loading branch information
asj authored and adam900710 committed Oct 11, 2024
1 parent bb1e846 commit dbabafa
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 dbabafa

Please sign in to comment.