From: Clemens Ladisch <clemens@ladisch.de>
To: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
Cc: alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org,
Dan Carpenter <error27@gmail.com>
Subject: Re: [patch] oxygen: clean up. make precedence explicit
Date: Fri, 19 Feb 2010 18:24:10 +0100 [thread overview]
Message-ID: <4B7EC93A.5010304@ladisch.de> (raw)
In-Reply-To: <1266584951.31443.15.camel@thorin>
Bernd Petrovitsch wrote:
> On Fre, 2010-02-19 at 14:29 +0300, Dan Carpenter wrote:
> > On Fri, Feb 19, 2010 at 11:33:30AM +0100, Bernd Petrovitsch wrote:
> > Basically often when people write:
> > if (!foo == bar) { ...
> >
> > What they mean is:
> > if (!(foo == bar)) { ...
But there are also cases where they mean what they've written.
> Ugh. The IMHO better way is
> if (foo != bar) { ...
In my case, the driver compares an "enabled" variable against a
"disabled" one; negating the comparison operator would obfuscate the
logic.
> > But if they really do mean the original code they could just write
> > this so it's clear to everyone:
> > if ((!foo) == bar) { ...
This is unnatural (especially in a simple example like this) because
the parens haven't been needed at all before smatch.
!foo==bar is always identical to !(foo==bar) for boolean values; to
avoid false positives, you could output the warning only when the code
is trying to manipulate non-boolean values. IMO the message would be
justified if it said "using suspicious boolean operations on non-boolean
types". (In fact, my driver uses types long and u8 in this expression,
so I will clean it up.)
Regards,
Clemens
WARNING: multiple messages have this Message-ID (diff)
From: Clemens Ladisch <clemens@ladisch.de>
To: Bernd Petrovitsch <bernd@petrovitsch.priv.at>
Cc: alsa-devel@alsa-project.org, kernel-janitors@vger.kernel.org,
Dan Carpenter <error27@gmail.com>
Subject: Re: [patch] oxygen: clean up. make precedence explicit
Date: Fri, 19 Feb 2010 17:24:10 +0000 [thread overview]
Message-ID: <4B7EC93A.5010304@ladisch.de> (raw)
In-Reply-To: <1266584951.31443.15.camel@thorin>
Bernd Petrovitsch wrote:
> On Fre, 2010-02-19 at 14:29 +0300, Dan Carpenter wrote:
> > On Fri, Feb 19, 2010 at 11:33:30AM +0100, Bernd Petrovitsch wrote:
> > Basically often when people write:
> > if (!foo = bar) { ...
> >
> > What they mean is:
> > if (!(foo = bar)) { ...
But there are also cases where they mean what they've written.
> Ugh. The IMHO better way is
> if (foo != bar) { ...
In my case, the driver compares an "enabled" variable against a
"disabled" one; negating the comparison operator would obfuscate the
logic.
> > But if they really do mean the original code they could just write
> > this so it's clear to everyone:
> > if ((!foo) = bar) { ...
This is unnatural (especially in a simple example like this) because
the parens haven't been needed at all before smatch.
!foo=bar is always identical to !(foo=bar) for boolean values; to
avoid false positives, you could output the warning only when the code
is trying to manipulate non-boolean values. IMO the message would be
justified if it said "using suspicious boolean operations on non-boolean
types". (In fact, my driver uses types long and u8 in this expression,
so I will clean it up.)
Regards,
Clemens
next prev parent reply other threads:[~2010-02-19 17:24 UTC|newest]
Thread overview: 16+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-19 8:29 [patch] oxygen: clean up. make precedence explicit Clemens Ladisch
2010-02-19 8:29 ` Clemens Ladisch
2010-02-19 10:10 ` Dan Carpenter
2010-02-19 10:10 ` Dan Carpenter
2010-02-19 10:33 ` Bernd Petrovitsch
2010-02-19 11:29 ` Dan Carpenter
2010-02-19 11:29 ` Dan Carpenter
2010-02-19 16:58 ` Dan Carpenter
2010-02-19 16:58 ` Dan Carpenter
2010-02-19 13:09 ` Bernd Petrovitsch
2010-02-19 17:24 ` Clemens Ladisch [this message]
2010-02-19 17:24 ` Clemens Ladisch
2010-02-19 20:08 ` Dan Carpenter
2010-02-19 20:08 ` Dan Carpenter
-- strict thread matches above, loose matches on Subject: below --
2010-02-19 6:58 Dan Carpenter
2010-02-19 6:58 ` Dan Carpenter
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=4B7EC93A.5010304@ladisch.de \
--to=clemens@ladisch.de \
--cc=alsa-devel@alsa-project.org \
--cc=bernd@petrovitsch.priv.at \
--cc=error27@gmail.com \
--cc=kernel-janitors@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 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.