From: Phil Sutter <phil@nwl.cc>
To: David Laight <David.Laight@ACULAB.COM>
Cc: Stephen Hemminger <shemming@brocade.com>,
Daniel Borkmann <daniel@iogearbox.net>,
David Ahern <dsa@cumulusnetworks.com>,
Nicolas Dichtel <nicolas.dichtel@6wind.com>,
Julien Floret <julien.floret@6wind.com>,
"netdev@vger.kernel.org" <netdev@vger.kernel.org>
Subject: Re: [iproute PATCH v3 6/6] misc/ifstat: simplify unsigned value comparison
Date: Fri, 24 Jun 2016 13:55:08 +0200 [thread overview]
Message-ID: <20160624115508.GC28345@orbyte.nwl.cc> (raw)
In-Reply-To: <063D6719AE5E284EB5DD2968C1650D6D5F4E3EA0@AcuExch.aculab.com>
On Fri, Jun 24, 2016 at 09:20:32AM +0000, David Laight wrote:
> From: Phil Sutter
> > Sent: 23 June 2016 18:34
> >
> > By directly comparing the value of both unsigned variables, casting to
> > signed becomes unnecessary.
> >
> > This also fixes for compiling with older versions of gcc (at least
> > <=3.4.6) which emit the following warning:
> >
> > | ifstat.c: In function `update_db':
> > | ifstat.c:542: warning: comparison is always false due to limited range of data type
> >
> > Signed-off-by: Phil Sutter <phil@nwl.cc>
> > ---
> > misc/ifstat.c | 2 +-
> > 1 file changed, 1 insertion(+), 1 deletion(-)
> >
> > diff --git a/misc/ifstat.c b/misc/ifstat.c
> > index abbb4e732fcef..9a44da487599e 100644
> > --- a/misc/ifstat.c
> > +++ b/misc/ifstat.c
> > @@ -539,7 +539,7 @@ static void update_db(int interval)
> > int i;
> >
> > for (i = 0; i < MAXS; i++) {
> > - if ((long)(h1->ival[i] - n->ival[i]) < 0) {
> > + if (h1->ival[i] < n->ival[i]) {
> > memset(n->ival, 0, sizeof(n->ival));
> > break;
>
> That isn't the same check.
> The original code is using modulo arithmetic.
Oh, right! The code behaves differently if h1->ival[i] is close to
ULONG_MAX and n->ival[i] is very small. Though I don't see where this
becomes relevant. Am I missing another scenario?
Thanks, Phil
next prev parent reply other threads:[~2016-06-24 11:54 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-06-23 17:34 [iproute PATCH v3 0/6] Big C99 style initializer rework Phil Sutter
2016-06-23 17:34 ` [iproute PATCH v3 1/6] tc: m_action: Improve conversion to C99 style initializers Phil Sutter
2016-06-23 17:34 ` [iproute PATCH v3 2/6] Use C99 style initializers everywhere Phil Sutter
2016-06-23 17:34 ` [iproute PATCH v3 3/6] Replace malloc && memset by calloc Phil Sutter
2016-06-23 17:34 ` [iproute PATCH v3 4/6] No need to initialize rtattr fields before parsing Phil Sutter
2016-06-23 17:34 ` [iproute PATCH v3 5/6] Makefile: Allow to override CC Phil Sutter
2016-06-23 17:34 ` [iproute PATCH v3 6/6] misc/ifstat: simplify unsigned value comparison Phil Sutter
2016-06-24 9:20 ` David Laight
2016-06-24 11:55 ` Phil Sutter [this message]
2016-06-24 9:17 ` [iproute PATCH v3 0/6] Big C99 style initializer rework David Laight
2016-06-24 11:47 ` Phil Sutter
2016-06-24 13:12 ` Nicolas Dichtel
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=20160624115508.GC28345@orbyte.nwl.cc \
--to=phil@nwl.cc \
--cc=David.Laight@ACULAB.COM \
--cc=daniel@iogearbox.net \
--cc=dsa@cumulusnetworks.com \
--cc=julien.floret@6wind.com \
--cc=netdev@vger.kernel.org \
--cc=nicolas.dichtel@6wind.com \
--cc=shemming@brocade.com \
/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).