home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #1 / NN_1993_1.iso / spool / comp / unix / aix / 13145 < prev    next >
Encoding:
Internet Message Format  |  1993-01-08  |  1.9 KB

  1. Path: sparky!uunet!cs.utexas.edu!wupost!gumby!destroyer!gatech!darwin.sura.net!cs.utk.edu!cs.utk.edu!moore
  2. From: moore@cs.utk.edu (Keith Moore)
  3. Newsgroups: comp.unix.aix
  4. Subject: Re: malloc(0) fails on AIX and nowhere else I could find ...
  5. Date: 8 Jan 1993 17:25:30 GMT
  6. Organization: Univ. of Tenn. Computer Science, Knoxville
  7. Lines: 28
  8. Distribution: world
  9. Message-ID: <1ikdebINN6qv@CS.UTK.EDU>
  10. References: <93Jan7.012526est.169557-2@watdragon.uwaterloo.ca> <C0HCs4.Eoy@axion.bt.co.uk>
  11. Reply-To: moore@cs.utk.edu
  12. NNTP-Posting-Host: yertle.cs.utk.edu
  13.  
  14. In article <C0HCs4.Eoy@axion.bt.co.uk>, nwinton@axion.bt.co.uk (Neil Winton) writes:
  15. > In article <93Jan7.012526est.169557-2@watdragon.uwaterloo.ca>, jmsellen@watdragon.uwaterloo.ca ("John M. Sellens") writes:
  16. > |> Just in case anyone is interested:
  17. > |> 
  18. > |> Trying to malloc() 0 bytes on AIX fails, but works on Ultrix, IRIX,
  19. > |> Dynix, SunOS, BSD, MIPS RiscOS.
  20. > Pardon?  What do you mean `it works'?  Sure it returns a non-null pointer but
  21. > what are you going to do with that?  You asked for no space to be allocated 
  22. > so how are you going to use that pointer-to-nothing??? 
  23.  
  24. Well, you could free() it.  Or realloc() it to a larger size later.
  25.  
  26. Say you're implementing a strings package and your string descriptor
  27. looks like struct string { int count; char *ptr }; Now when you assign
  28. to a string you want to malloc (or realloc) the right # of bytes and
  29. assign the return value from malloc to the ptr.  But with AIX (and
  30. many other SysV-based systems), you have to explicitly test in case
  31. the string you want to assign is zero length.
  32.  
  33. Saying you shouldn't be able to malloc() zero bytes is like saying you
  34. shouldn't be able to have a zero-length file, or an empty record in a
  35. file, or you shouldn't be able to multiply something by zero.
  36.  
  37. To be fair, AIX isn't unique in this regard -- most SysV based systems
  38. work this way.  Like most of the features unique to SysV, this one is
  39. a botch.
  40.  
  41.