Return value of malloc(0)

Harti Brandt hartmut.brandt at dlr.de
Thu Jun 29 17:23:18 UTC 2006


On Thu, 29 Jun 2006, Johannes Weiner wrote:

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

Wouldn't it rather invoke undefined behaviour?

harti


More information about the freebsd-hackers mailing list