Subject: Re: [PATCH iproute2 3/5] ss: fix warning about empty if()

From: Petr Machata <[email-masked]>
Date: Thu, 29 Jun 2023 15:14:27 +0200

Stephen Hemminger <[email-masked]> 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 <[email-masked]>
> ---
>  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 <[email-masked]>

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.