netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ben Hutchings <bhutchings@solarflare.com>
To: Eric Dumazet <eric.dumazet@gmail.com>
Cc: Christoph Paasch <christoph.paasch@uclouvain.be>,
	Stephen Hemminger <stephen@networkplumber.org>,
	<netdev@vger.kernel.org>
Subject: Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values
Date: Mon, 22 Jul 2013 18:26:37 +0100	[thread overview]
Message-ID: <1374513997.1635.22.camel@bwh-desktop.uk.level5networks.com> (raw)
In-Reply-To: <1374507539.4990.17.camel@edumazet-glaptop>

On Mon, 2013-07-22 at 08:38 -0700, Eric Dumazet wrote:
> On Sat, 2013-07-20 at 21:58 +0200, Christoph Paasch wrote:
> > Many errors when compiling with gcc 4.7.3 about unused return-values
> > upon the calls to fgets and fscanf:
> >
> 
> > For the calls to fscanf we can't really do anything about it, and just
> > do an empty if-statement to make the compiler happy.
> > 
> > Signed-off-by: Christoph Paasch <christoph.paasch@uclouvain.be>
> > ---
> >  misc/ss.c | 30 +++++++++++++++++++++---------
> >  1 file changed, 21 insertions(+), 9 deletions(-)
> > 
> > diff --git a/misc/ss.c b/misc/ss.c
> > index c0369f1..0f71108 100644
> > --- a/misc/ss.c
> > +++ b/misc/ss.c
> > @@ -302,7 +302,7 @@ static void user_ent_hash_build(void)
> >  
> >  				snprintf(tmp, sizeof(tmp), "%s/%d/stat", root, pid);
> >  				if ((fp = fopen(tmp, "r")) != NULL) {
> > -					fscanf(fp, "%*d (%[^)])", process);
> > +					if (fscanf(fp, "%*d (%[^)])", process) == EOF);
> 
> This is really ugly :(

It is.  And gcc doesn't accept casting to void to suppress the warning.
Maybe add a wrapper fscanf_with_output_already_set_to_default()? ;-)  Or
do what glibc expects and set the defaults only when fscanf() reads less
than we wanted:

	switch (fscanf(p, "...", &foo, &bar, ...)) {
	case EOF:
	case 0: foo = ...;
	case 1: bar = ...;
	...
	}

Ben.

-- 
Ben Hutchings, Staff Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.

  reply	other threads:[~2013-07-22 17:26 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-20 19:58 [PATCH iproute2 0/2] Fix compiler-errors with gcc 4.7.3 Christoph Paasch
2013-07-20 19:58 ` [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values Christoph Paasch
2013-07-22 14:54   ` Stephen Hemminger
2013-07-22 15:06     ` Denis Kirjanov
2013-07-22 15:35       ` Stephen Hemminger
2013-07-22 15:14     ` Christoph Paasch
2013-07-22 15:38   ` Eric Dumazet
2013-07-22 17:26     ` Ben Hutchings [this message]
2013-07-20 19:58 ` [PATCH iproute2 2/2] lnstat: " Christoph Paasch

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=1374513997.1635.22.camel@bwh-desktop.uk.level5networks.com \
    --to=bhutchings@solarflare.com \
    --cc=christoph.paasch@uclouvain.be \
    --cc=eric.dumazet@gmail.com \
    --cc=netdev@vger.kernel.org \
    --cc=stephen@networkplumber.org \
    --subject='Re: [PATCH iproute2 1/2] ss: Fix compiler errors of unused return-values' \
    /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

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).