From: H.J. Lu (hlu@yoda.eecs.wsu.edu)
Date: 11/21/92


From: hlu@yoda.eecs.wsu.edu (H.J. Lu)
Subject: malloc (0) ( Re: function-->macro bugs.)
Date: 21 Nov 1992 10:21:53 GMT

FYI, there were no malloc macros in stdlib.h when I first started C
library. People were having trouble with malloc (0) returns NULL.
There was a lenthy discussion about it at that time. I asked
the author of malloc. He told me

1. malloc (0) returns NULL is ok under POSIX.
2. change malloc.c will break either POSIX or ANSI.

We deiced that putting macros with -DNO_FIX_MALLOC to turn them off
is much better than any other alternatives we could think of at
the time.

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. Please don't ask me to fix the source
code by doing

        p = malloc (len ? len : 1); /* len may be 0. */
        if (!p) fatal ("Out of memory");

You should expect there are lots of such kind of codes around. I
thought we were done last time. We now started all over again :-(.

H.J.