From: Lars Wirzenius (wirzeniu@klaava.Helsinki.FI)
Date: 11/21/92


From: wirzeniu@klaava.Helsinki.FI (Lars Wirzenius)
Subject: Re: malloc (0) ( Re: function-->macro bugs.)
Date: 21 Nov 1992 12:45:29 GMT

hlu@yoda.eecs.wsu.edu (H.J. Lu) writes:
>1. malloc (0) returns NULL is ok under POSIX.

Under ANSI/ISO C too. OTOH, malloc(0) != NULL are ok by everybody as
well.

>If you can come up with a better idea to deal with
>
> p = malloc (len); /* len may be 0. */
> if (!p) fatal ("Out of memory");
>
>I'd like to hear from you.

There are programs which assume that malloc(0)==NULL, and programs
which assume malloc(0)!=NULL. We can't support both types at the same
time without some kinds of hacks, something will surely break.

I have no problems with the current scheme (except for some naming
choices, I'd prefer __MALLOC_0_IS_NON_NULL instead of NO_FIX_MALLOC).
Fixing programs that try to substitute their own malloc shouldn't be
that hard. We'll never achieve total compatibility with all current
source code anyway.