Re: [PATCH] Staging: rtl8188eu: Remove zero testing pointer typed value

From: Dan Carpenter
Date: Fri Apr 03 2015 - 17:05:22 EST


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
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/