lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite for Android: free password hash cracker in your pocket
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Pine.LNX.4.61.0705271655450.7344@yvahk01.tjqt.qr>
Date:	Sun, 27 May 2007 17:02:10 +0200 (MEST)
From:	Jan Engelhardt <jengelh@...ux01.gwdg.de>
To:	Stefan Richter <stefanr@...6.in-berlin.de>
cc:	Auke Kok <auke-jan.h.kok@...el.com>, randy.dunlap@...cle.com,
	Linux Kernel Mailing List <linux-kernel@...r.kernel.org>,
	Scott Preece <sepreece@...il.com>
Subject: Re: [PATCH] [condingstyle] Add chapter on tests


On May 27 2007 16:37, Stefan Richter wrote:
>Jan Engelhardt wrote:
>> +	if (is_prime(number) == true)
>> +		return 0;
>> +	if (is_prime(number) == false)
>> +		return 1;
>> +
>> +should be:
>> +
>> +	if (is_prime(number))
>> +		return 0;
>> +	if (!is_prime(number))
>> +		return 1;
>> +
>> +As far as pointers or functions returning an integer are concerned,
>> +using long form tests helps to distinguish between pointers and bools
>> +or functions returning boolean or integer, respectively.
>> +Examples are:
>> +
>> +	if (p == NULL)
>> +		return 1;
>> +	if (!p)
>> +		return 0;
>> +
>> +	if (strcmp(haystack, needle) == 0)
>> +		return 1;
>> +	if (!strcmp(haystack, needle))
>> +		return 0;
>
>The latter two examples seem odd.  Didn't you mean the following?

See how much confusion it all makes!

Right, it was intended -- first the long form is shown and then the
shorter one (and "long form tests help to distinguish"):

	if (p == NULL)	/* this way please */
		return 1;
	if (!p)		/* Everytime you shorten it, God kills a kitten */
		return 0;
		/* so perhaps don't do it if you love animals or
		know someone who does. */

I seem to have forgotten more comments/explanation.

>	if (p == NULL)
>		return 1;
>	if (p)
>		return 0;
>
>	if (strcmp(haystack, needle) == 0)
>		return 1;
>	if (strcmp(haystack, needle))
>		return 0;
>
>Perhaps better:
>
>	if (p == NULL)
>		return NO_MEMORY;
>	if (p)
>		return MEMORY;
>
>	if (strcmp(haystack, needle) == 0)
>		return IS_SAME;
>	if (strcmp(haystack, needle))
>		return IS_DIFFERENT;
>
>However, to follow your argument about non-boolean expressions, the
>following would be more consequently going into your direction:
>
>I.e., why do the explicit comparison with 0 or NULL only when it is
>tested for equality, but not when testing for inequality?
>
>However, I agree with Scott Preece that these rules should be left out
>of CodingStyle because they are contentious.
>
>(Disclosure:  I am personally used to "if (p)" and "if (!p)" tests of
>pointers and many integer expressions, but I tend to the longer form in
>less obvious cases like "if (strcmp(a, b) != 0)".)



	Jan
-- 
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ