home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.unix.aix
- Path: sparky!uunet!cs.utexas.edu!geraldo.cc.utexas.edu!portal.austin.ibm.com!awdprime.austin.ibm.com!codesmith.austin.ibm.com!dcm
- From: dcm@codesmith.austin.ibm.com (Craig Miller - dcm@austin.ibm.com)
- Subject: Re: malloc(0) fails on AIX and nowhere else I could find ...
- Sender: news@austin.ibm.com (News id)
- Message-ID: <C0LnII.pGK@austin.ibm.com>
- Date: Sat, 9 Jan 1993 18:32:42 GMT
- References: <1ikdebINN6qv@CS.UTK.EDU> <C0JvG9.1HBs@austin.ibm.com> <4512@unisql.UUCP>
- Organization: IBM AWD, Austin
- Lines: 29
-
- In article <4512@unisql.UUCP> wrat@unisql.UUCP (wharfie) writes:
- >In article <C0JvG9.1HBs@austin.ibm.com> dcm@codesmith.austin.ibm.com (Craig Miller - dcm@austin.ibm.com) writes:
- >>those who support malloc(0): ptr = malloc(length);
- >>those who don't: ptr = (length == 0) ? NULL : malloc(length);
- >>
- >>Right? And the second case *always* works, regardless of whether the
- >>local implementation of malloc supports malloc(0) or not. Right?
- >
- > Nope. Most code that expects malloc(0) to return a pointer to
- >0 bytes does something like
- >
- > if (!(ptr=malloc(foo))) goto NO_MEMORY;
-
- My example still works. Always. However, I think I understand
- what you're saying. It should be something like:
-
- if (length == 0)
- ptr = NULL;
- else if ((ptr = malloc(length)) == NULL)
- goto NO_MEMORY;
-
- Still, code that depends on any particular behavior of malloc(0)
- is unportable. Period.
-
- Craig
- --
- Craig Miller, software mechanic: AIXV3 Change Team (Level3 support)
- #include <ibm/stds/disclaimer.h>
- char *internet = "dcm@austin.ibm.com", *vnet = "AUSVM6(TKG007)";
-