netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Petr Machata <me@pmachata.org>
To: Stephen Hemminger <stephen@networkplumber.org>
Cc: netdev@vger.kernel.org
Subject: Re: [PATCH iproute2 3/5] ss: fix warning about empty if()
Date: Thu, 29 Jun 2023 15:14:27 +0200	[thread overview]
Message-ID: <87pm5ee699.fsf@nvidia.com> (raw)
In-Reply-To: <20230628233813.6564-4-stephen@networkplumber.org>


Stephen Hemminger <stephen@networkplumber.org> writes:

> With all warnings enabled gcc wants brackets around the
> empty if() clause. "Yes I really want an empty clause"
>
> Signed-off-by: Stephen Hemminger <stephen@networkplumber.org>
> ---
>  misc/ss.c | 3 ++-
>  1 file changed, 2 insertions(+), 1 deletion(-)
>
> diff --git a/misc/ss.c b/misc/ss.c
> index de02fccb539b..e9d813596b91 100644
> --- a/misc/ss.c
> +++ b/misc/ss.c
> @@ -627,8 +627,9 @@ static void user_ent_hash_build_task(char *path, int pid, int tid)
>  
>  			fp = fopen(stat, "r");
>  			if (fp) {
> -				if (fscanf(fp, "%*d (%[^)])", task) < 1)
> +				if (fscanf(fp, "%*d (%[^)])", task) < 1) {
>  					; /* ignore */
> +				}
>  				fclose(fp);
>  			}
>  		}

Reviewed-by: Petr Machata <me@pmachata.org>

As an aside, this whole if business is necessary in the first place due
to __attribute__((warn_unused_result)) that fscanf apparently has on
some libc's. But ignoring fscanf failures is safe, because a) `task' is
pre-initialized at variable definition, so ignoring the result like this
should indeed be safe; and b), fp references some file in /proc and we
can rely on the format and that the scan will in fact not fail.

  reply	other threads:[~2023-06-29 13:40 UTC|newest]

Thread overview: 12+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-06-28 23:38 [PATCH iproute2 0/5] Warning fixes Stephen Hemminger
2023-06-28 23:38 ` [PATCH iproute2 1/5] dcb: fully initialize flag table Stephen Hemminger
2023-06-29 13:08   ` Petr Machata
2023-06-28 23:38 ` [PATCH iproute2 2/5] fix fallthrough warnings Stephen Hemminger
2023-06-29 13:54   ` Petr Machata
2023-06-28 23:38 ` [PATCH iproute2 3/5] ss: fix warning about empty if() Stephen Hemminger
2023-06-29 13:14   ` Petr Machata [this message]
2023-06-28 23:38 ` [PATCH iproute2 4/5] ct: check for invalid proto Stephen Hemminger
2023-06-29 13:44   ` Petr Machata
2023-06-28 23:38 ` [PATCH iproute2 5/5] ifstat: fix warning about conditional Stephen Hemminger
2023-06-29 13:49   ` Petr Machata
2023-06-29 16:10 ` [PATCH iproute2 0/5] Warning fixes patchwork-bot+netdevbpf

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=87pm5ee699.fsf@nvidia.com \
    --to=me@pmachata.org \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.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;
as well as URLs for NNTP newsgroup(s).