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: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Date:	Wed, 26 Jan 2011 07:29:42 -0200
From:	Mauro Carvalho Chehab <mchehab@...radead.org>
To:	Peter Hüwe <PeterHuewe@....de>
CC:	Julia Lawall <julia@...u.dk>, linux-media@...r.kernel.org,
	linux-kernel@...r.kernel.org, kernel-janitors@...r.kernel.org,
	Steven Toth <stoth@...nellabs.com>, Tejun Heo <tj@...nel.org>,
	Dan Carpenter <error27@...il.com>
Subject: Re: [PATCH] video/saa7164: Fix sparse warning: Using plain integer
 as NULL pointer

Em 25-01-2011 20:54, Peter Hüwe escreveu:
> Am Dienstag 25 Januar 2011, 23:20:44 schrieb Julia Lawall:
>> On Tue, 25 Jan 2011, Peter Huewe wrote:
>>> This patch fixes the warning "Using plain integer as NULL pointer",
>>> generated by sparse, by replacing the offending 0s with NULL.
>>
>> I recall (a number of years ago) being told that for things like kmalloc,
>> the proper test was !x, not x == NULL.
>>
>> julia
>>
> 
> 
> Hi Julia,
> 
> thanks for your input.
> So do I understand you correctly if I say
> if(!x) is better than if(x==NULL) in any case?
> 
> Or only for the kmalloc family?
> 
> Do you remember the reason why !x should be preferred?
> 
> In Documentation/CodingStyle ,  Chapter 7: Centralized exiting of functions 
> there is a function fun with looks like this:
> int fun(int a)
> {
>     int result = 0;
>     char *buffer = kmalloc(SIZE);
> 
>     if (buffer == NULL)
>         return -ENOMEM;
> 
>     if (condition1) {
>         while (loop1) {
>             ...
>         }
>         result = 1;
>         goto out;
>     }
>     ...
> out:
>     kfree(buffer);
>     return result;
> }
> 
> 
> -->  So   if (buffer == NULL) is in the official CodingStyle - maybe we should 
> add a paragraph there as well ;)
> 
> 
> Don't get me wrong, I just want to learn ;)

Both ways are acceptable. But because C is a Spartan language, and because
I need to review lots of code, I prefer the more synthetic way:
	if (!buf)

That means less things to read, and saves me a few microsseconds of reading
and processing it on my mind. In general, such tests occur just after a malloc
or a malloc-like function, so it is really obvious that you're testing for
a pointer.

Cheers,
Mauro
--
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