All of lore.kernel.org
 help / color / mirror / Atom feed
From: Tilman Schmidt <tilman@imap.cc>
To: Satyam Sharma <satyam.sharma@gmail.com>
Cc: Roland Dreier <rdreier@cisco.com>,
	openib-general@openib.org, linux-kernel@vger.kernel.org
Subject: Re: dealing with gcc 'comparison is always false' warnings
Date: Wed, 30 May 2007 21:00:57 +0200	[thread overview]
Message-ID: <465DC9E9.3040904@imap.cc> (raw)
In-Reply-To: <a781481a0705300841k2a02335eg66985129eaed28f4@mail.gmail.com>

[-- Attachment #1: Type: text/plain, Size: 1850 bytes --]

Am 30.05.2007 17:41 schrieb Satyam Sharma:
> On 5/30/07, Roland Dreier <rdreier@cisco.com> wrote:
>> thanks... I'm wondering if there's a consensus among kernel hackers
>> about changes like:
>>
>>  > -    if (hdr.cmd < 0 || hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
>>  > +    if (hdr.cmd >= ARRAY_SIZE(ucma_cmd_table))
>>  >              return -EINVAL;
>>
>> I understand that new gcc sees that hdr.cmd is unsigned and hence
>> can't be < 0, and generates a warning for that, and having a build
>> cluttered with warnings hides bugs and so on.  However the code here
>> looks quite sensible to me -- otherwise we end up with missing range
>> checking if hdr.cmd ever changes to a signed type.  This seems like a
>> good way to introduce bugs: delete valid range checking code to shut
>> up a silly gcc warning, and then change the type of a variable.
> 
> You're *absolutely* correct about the issue that these "fixes" that remove
> such conditions end up remove range-checking making the code more
> flakey / less readable.

I disagree. Changing the type of a variable is a significant
modification. If someone does that, he or she *must* check every
use of that variable, at which point he or she will also modify
any range checks accordingly. Having checks that don't fit with
the previous type *distracts* from that job. "Oh, did I modify
that part already? Guess I can skip checking the rest of that
function then." Oops.

Nor is readability a suitable argument. Checking if hdr.cmd is
less than zero gives the misleading impression that it *could*
be less than zero, thus *impairing* readability.

jm2c
T.

-- 
Tilman Schmidt                          E-Mail: tilman@imap.cc
Bonn, Germany
Diese Nachricht besteht zu 100% aus wiederverwerteten Bits.
Ungeöffnet mindestens haltbar bis: (siehe Rückseite)


[-- Attachment #2: OpenPGP digital signature --]
[-- Type: application/pgp-signature, Size: 253 bytes --]

  parent reply	other threads:[~2007-05-30 18:57 UTC|newest]

Thread overview: 11+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-30  8:05 [PATCH] drivers/infiniband: fix comparsion between unsigned and negative Bill Nottingham
2007-05-30 15:30 ` dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative) Roland Dreier
2007-05-30 15:41   ` Satyam Sharma
2007-05-30 15:56     ` [ofa-general] Re: dealing with gcc 'comparison is always false' warnings Roland Dreier
2007-05-30 17:00       ` Satyam Sharma
2007-05-30 16:06     ` dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative) Satyam Sharma
2007-05-30 19:00     ` Tilman Schmidt [this message]
2007-05-30 19:14       ` dealing with gcc 'comparison is always false' warnings Satyam Sharma
2007-05-30 19:09     ` dealing with gcc 'comparison is always false' warnings (was: [PATCH] drivers/infiniband: fix comparsion between unsigned and negative) Bill Nottingham
2007-05-30 19:23       ` Satyam Sharma
2007-05-30 20:48 ` [ofa-general] [PATCH] drivers/infiniband: fix comparsion between unsigned and negative Roland Dreier

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=465DC9E9.3040904@imap.cc \
    --to=tilman@imap.cc \
    --cc=linux-kernel@vger.kernel.org \
    --cc=openib-general@openib.org \
    --cc=rdreier@cisco.com \
    --cc=satyam.sharma@gmail.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.