btrfs-progs: fix compiler warning when usage string is NULL

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 <wqu@suse.com>
Signed-off-by: Anand Jain <anand.jain@oracle.com>
This commit is contained in:
Anand Jain 2024-10-11 12:17:19 +08:00 committed by David Sterba
parent 5a0dff507f
commit cad1db97c5
1 changed files with 2 additions and 2 deletions

View File

@ -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;
}