Re: [PATCH tabled] server/server.c don't deref NULL on failed malloc

Jeff Garzik <[email protected]> Thu, 23 Sep 2010 15:41:08 -0400
Newsgroups org.kernel.vger.hail-devel
Message-ID <[email protected]>
On 09/23/2010 10:07 AM, Pete Zaitcev wrote:
> On Thu, 23 Sep 2010 13:03:15 +0200
> Jim Meyering<[email protected]>  wrote:
>
>> Just noticed that sometimes tabled uses this idiom:
>>    if (!(key = malloc(klen + 1)))
>> and sometimes this:
>>    if ((key = malloc(klen + 1)) == NULL)
>> This time I used "... == NULL".
>
> Er... The bang is Jeff's, which I try to follow always, but perhaps
> one or two slipped due to opposing habit. IIRC pathtokey() was mine.
> In fact tabled does not use assignments in conditions, dunno why
> but it's a tradition.

I always considered assignments in conditionals as fragile and 
error-prone, and try to avoid them.  However, I occasionally break my 
own rule, such as with fgets(3) or getopt(3) loops.

And, getting back on topic, I do prefer implicit rather than explicit 
testing for zero and non-zero...  but that too is a "weak preference" 
where I won't complain much if somebody else does it.

Typically the general rule for any codebase is "try to look like the 
rest of the codebase."

	Jeff