Re: Return value of malloc(0)



Johannes Weiner <hnazfoo@xxxxxxxxxxxxxx> 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@xxxxxxxxxxx mailing list
http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@xxxxxxxxxxx"



Relevant Pages

  • Re: The best road(s) in the world, ever?
    ... Krusty wrote: ... >> I can assume sir hasn't ridden the 999, ... but if you compare it on a map to the N260 I think you'll ...
    (uk.rec.motorcycles)
  • Smacking is obsolete (Re: hey pig i might get a dog for my kid)
    ... spanking wasn't effective at all? ... if you compare em side by side its like night and day. ... yes sir no ... Disrespectful parents beget disrespectful children. ...
    (soc.culture.filipino)
  • 1+i > i
    ... i know that complex numbers can't compare about size. ... but this process is very plausible as paradox. ... thank you very much your advice. ... thank you, sir~ ...
    (sci.math)