From: Dan Carpenter <dan.carpenter@oracle.com>
To: Joe Perches <joe@perches.com>
Cc: devel@driverdev.osuosl.org, gregkh@linuxfoundation.org,
Amitoj Kaur Chawla <amitoj1606@gmail.com>,
linux-kernel@vger.kernel.org
Subject: Re: [PATCH] Staging: rtl8188eu: Remove zero testing pointer typed value
Date: Sat, 4 Apr 2015 00:04:59 +0300 [thread overview]
Message-ID: <20150403210458.GV10964@mwanda> (raw)
In-Reply-To: <1428080470.13180.19.camel@perches.com>
On Fri, Apr 03, 2015 at 10:01:10AM -0700, Joe Perches wrote:
> On Fri, 2015-04-03 at 19:51 +0300, Dan Carpenter wrote:
> > Also strcmp() and similar should always be done as == 0, < 0 or != 0
> > because that is the idiom:
>
> Less true.
>
> When testing for equality, !strcmp is very common.
>
> There are ~2500 uses of !strcmp in the kernel tree vs
> ~1500 uses of strcmp() == or !=
Bugs with reversed strcmp() tests are almost always caught in testing so
it's not an issue. But == 0 is more correct. ;)
1) It's more clear when read in English. "if not strcmp then" or
"if strcmp NOT EQUAL zero". In the second one I've emphasized the
NOT EQUAL because the strings are not eqaul.
2) Also if works for the other compares too.
if (strcmp(x, y) < 0) <-- means x is less than y.
if (strcmp(x, y) == 0) <-- means x == y.
regards,
dan carpenter
next prev parent reply other threads:[~2015-04-03 21:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2015-04-03 16:42 [PATCH] Staging: rtl8188eu: Remove zero testing pointer typed value Amitoj Kaur Chawla
2015-04-03 16:51 ` Dan Carpenter
2015-04-03 17:01 ` Joe Perches
2015-04-03 21:04 ` Dan Carpenter [this message]
2015-04-04 13:58 ` Dan Carpenter
2015-04-04 15:52 ` Joe Perches
2015-04-03 17:03 ` Amitoj Kaur Chawla
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=20150403210458.GV10964@mwanda \
--to=dan.carpenter@oracle.com \
--cc=amitoj1606@gmail.com \
--cc=devel@driverdev.osuosl.org \
--cc=gregkh@linuxfoundation.org \
--cc=joe@perches.com \
--cc=linux-kernel@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