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