public inbox for smatch@vger.kernel.org
 help / color / mirror / Atom feed
From: John Levon <levon@movementarian.org>
To: Dan Carpenter <dan.carpenter@oracle.com>
Cc: smatch@vger.kernel.org
Subject: Re: check_signed.c false negative
Date: Wed, 13 Nov 2019 17:52:33 +0000	[thread overview]
Message-ID: <20191113175233.GA11603@movementarian.org> (raw)
In-Reply-To: <20191112055759.GA1959@kadam.lan>

On Wed, Nov 13, 2019 at 08:39:13PM +0300, Dan Carpenter wrote:

> On Mon, Nov 11, 2019 at 11:21:15PM +0000, John Levon wrote:
> > 
> > Given:
> > 
> > enum ib_qp_state {
> >         IB_QPS_RESET,
> >         IB_QPS_INIT,
> >         IB_QPS_RTR,
> >         IB_QPS_RTS,
> >         IB_QPS_SQD,
> >         IB_QPS_SQE,
> >         IB_QPS_ERR
> > };
> > 
> > int p(enum ib_qp_state cur_state, enum ib_qp_state next_state)
> > {
> > #if 0
> >        if (cur_state  < 0 || cur_state > IB_QPS_ERR ||
> >          next_state < 0 || next_state > IB_QPS_ERR) {
> >                 return (5);
> >         }
> > #else
> >        if (next_state < 0 || next_state > IB_QPS_ERR) {
> >                 return (5);
> >         }
> > #endif
> > 
> >         return (0);
> > }
> > 
> > current smatch is happy. But "#if 1" above instead, and:
> > 
> > jlevon@sent:~/src/smatch$ ./smatch a.c
> > ./smatch: a.c:15 p() warn: unsigned 'cur_state' is never less than zero.
> > 
> > Why is "next_state" not reported equally?
> 
> My plan was that neither one would print a warning.  When people do
> 
> 	if (foo < 0 || foo > max)
> 
> then normally it's not a real life bug...  Linus said at kernel summit
> that he doesn't like when people send patches for those.

Right, in fact the code this comes from is similar: it's a
belt-and-braces check that we didn't somehow get a bad state value.

There's definitely other cases where this might be useful, though I
wouldn't object to disabling it by default altogether.

thanks
john

      reply	other threads:[~2019-11-13 17:52 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-11-11 23:21 check_signed.c false negative John Levon
2019-11-13 17:39 ` Dan Carpenter
2019-11-13 17:52   ` John Levon [this message]

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=20191113175233.GA11603@movementarian.org \
    --to=levon@movementarian.org \
    --cc=dan.carpenter@oracle.com \
    --cc=smatch@vger.kernel.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