Return value of malloc(0)

joerg at britannica.bec.de joerg at britannica.bec.de
Wed Jun 28 21:57:34 UTC 2006


On Wed, Jun 28, 2006 at 08:10:45PM +0200, Andre Albsmeier wrote:
> (Now malloc returns NULL and firefox doesn't interpret the
> result as a pointer to some allocated memory and therefore
> doesn't use it).

Return NULL for malloc(0) is one of two possible implementations. The
other behaviour is to generate a unique pointer for each call. Both
behaviours are intentionally allowed by the standard and code making
assumptions about either is broken.

It should be added that returning NULL for malloc(0) is consistent with
realloc, so it is actually nicer.

Joerg


More information about the freebsd-hackers mailing list