standards/62858: malloc(0) not C99 compliant

David Schultz das at FreeBSD.ORG
Mon Mar 1 08:01:18 PST 2004


On Mon, Mar 01, 2004, Poul-Henning Kamp wrote:
> In message <xzpznb0iwm0.fsf at dwp.des.no>, Dag-Erling =?iso-8859-1?q?Sm=F8rgrav?=
>  writes:
> >Poul-Henning Kamp <phk at FreeBSD.org> writes:
> >> This is a deliberate choice.  Handling zero-size pointers correctly
> >> in malloc(3) would be a rather involved and is currently not high
> >> on the todolist.  A good patch might change that.
> >
> >The standard does allow returning NULL, you know.
> 
> Yes, but unfortunately that broke more software than I cared for
> arguing with authors about.

Several other malloc implementations do this, including the one in
Tru64.  But assuming that there really are lots of broken
applications out there, what's wrong with simply converting
malloc(0) calls to malloc(1) calls?


More information about the freebsd-standards mailing list