home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / os / linux / 17438 < prev    next >
Encoding:
Internet Message Format  |  1992-11-20  |  1.4 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!uwm.edu!ogicse!news.u.washington.edu!serval!yoda.eecs.wsu.edu!hlu
  2. From: hlu@yoda.eecs.wsu.edu (H.J. Lu)
  3. Newsgroups: comp.os.linux
  4. Subject: malloc (0) ( Re: function-->macro bugs.)
  5. Message-ID: <1992Nov21.102153.15162@serval.net.wsu.edu>
  6. Date: 21 Nov 92 10:21:53 GMT
  7. Article-I.D.: serval.1992Nov21.102153.15162
  8. References: <By0ows.95I@news.cso.uiuc.edu> <1992Nov21.000241.9744@klaava.Helsinki.FI>
  9. Sender: news@serval.net.wsu.edu (USENET News System)
  10. Organization: Washington State University
  11. Lines: 27
  12.  
  13. FYI, there were no malloc macros in stdlib.h when I first started C
  14. library. People were having trouble with malloc (0) returns NULL.
  15. There was a lenthy discussion about it at that time. I asked
  16. the author of malloc. He told me
  17.  
  18. 1. malloc (0) returns NULL is ok under POSIX.
  19. 2. change malloc.c will break either POSIX or ANSI.
  20.  
  21. We deiced that putting macros with -DNO_FIX_MALLOC to turn them off
  22. is much better than any other alternatives we could think of at
  23. the time.
  24.  
  25. If you can come up with a better idea to deal with
  26.  
  27.     p = malloc (len); /* len may be 0. */
  28.     if (!p) fatal ("Out of memory");
  29.  
  30. I'd like to hear from you. Please don't ask me to fix the source
  31. code by doing
  32.  
  33.     p = malloc (len ? len : 1); /* len may be 0. */
  34.     if (!p) fatal ("Out of memory");
  35.  
  36. You should expect there are lots of such kind of codes around. I 
  37. thought we were done last time. We now started all over again :-(.
  38.  
  39. H.J.
  40.