Johannes Weiner <[EMAIL PROTECTED]> writes:

> On Thu, Jun 29, 2006 at 06:09:37PM +0200, Matthias Andree wrote:
>
>> The value returned from malloc(0) must not be dereferenced whatever it
>> was. It was 0x800, which doesn't count as "failure".
>
> But this would be appropriate for catching the error:
>
> if ((foo = malloc(0)) == foo)
>       /* make noise */
>
> wouldn't it?

No, sir. Operator precedence: assign first, and then compare, thus the
comparison will always be true (else you'd be comparing to undefined
values, which isn't any better).  You might as well write:

 foo = malloc(0);
 /* make noise */

There is no way to see a 0x800 return from malloc(0) as "error".

-- 
Matthias Andree
_______________________________________________
freebsd-hackers@freebsd.org mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "[EMAIL PROTECTED]"

Reply via email to