Linux Btrfs filesystem development
 help / color / mirror / Atom feed
From: Qu Wenruo <quwenruo.btrfs@gmx.com>
To: Anand Jain <anand.jain@oracle.com>, linux-btrfs@vger.kernel.org
Subject: Re: [PATCH] btrfs-progs: fix usage warning in common/help.c
Date: Fri, 11 Oct 2024 15:09:45 +1030	[thread overview]
Message-ID: <32dc259a-4ec0-4582-9c2f-666b56ff1db5@gmx.com> (raw)
In-Reply-To: <3ec35c42add1b57d547c9cbd90213a645c7335c9.1728459736.git.anand.jain@oracle.com>



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


      reply	other threads:[~2024-10-11  4:39 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
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 message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=32dc259a-4ec0-4582-9c2f-666b56ff1db5@gmx.com \
    --to=quwenruo.btrfs@gmx.com \
    --cc=anand.jain@oracle.com \
    --cc=linux-btrfs@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox