Message ID | 20230628233813.6564-4-stephen@networkplumber.org (mailing list archive) |
---|---|
State | Accepted |
Commit | 27dce6de940ab8b65bea4a41629af8ebe854232f |
Delegated to: | David Ahern |
Headers | show |
Series | Warning fixes | expand |
Context | Check | Description |
---|---|---|
netdev/tree_selection | success | Not a local patch |
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.
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); } }
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(-)