home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!news.u.washington.edu!serval!yoda.eecs.wsu.edu!hlu
- From: hlu@yoda.eecs.wsu.edu (H.J. Lu)
- Newsgroups: comp.os.linux
- Subject: malloc (0) ( Re: function-->macro bugs.)
- Message-ID: <1992Nov21.102153.15162@serval.net.wsu.edu>
- Date: 21 Nov 92 10:21:53 GMT
- Article-I.D.: serval.1992Nov21.102153.15162
- References: <By0ows.95I@news.cso.uiuc.edu> <1992Nov21.000241.9744@klaava.Helsinki.FI>
- Sender: news@serval.net.wsu.edu (USENET News System)
- Organization: Washington State University
- Lines: 27
-
- 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.
-