Article View: gnu.g++.bug
Article #150Re: 2.2.2 on rs6000: new[0] - gnu.g++.bug #4579
From: Tom McConnell
Date: Mon, 03 Aug 1992 01:16
Date: Mon, 03 Aug 1992 01:16
73 lines
3578 bytes
3578 bytes
Reply-To: tmcconne@sedona.intel.com
In article <9208022010.AA07155@cs.rice.edu>, dougm@cs.rice.edu (Doug Moore) writes:
> Attempting to allocate a zero-sized array on an rs6000 model 550
> results in a runtime error. This is aix3.2, with the patched
> assembler. g++ 2.2.2 with many patches off the net (although the
> problem has been around for a while, before 2.2.2 even).
>
> In quick succession, the verbose compile, the run, and the source
> follow.
>
> Doug Moore
> (dougm@cs.rice.edu)
>
>
> <masc41>:dougm % g++ -v -Wall junk.cc
> Reading specs from /import/blossom/lib/gcc-lib/rs6000/2.2.2/specs
> gcc version 2.2.2
> /import/blossom/lib/gcc-lib/rs6000/2.2.2/cpp -lang-c++ -v -undef -D__GNUC__=2 -
> D__GNUG__=2 -D__cplusplus -D_IBMR2 -D_AIX -D___IBMR2__ -D___AIX__ -D___IBMR2 -D_
> __AIX -D__CHAR_UNSIGNED__ -Wall junk.cc /tmp/ccJo4Daw.i
> GNU CPP version 2.2.2
> /import/blossom/lib/gcc-lib/rs6000/2.2.2/cc1plus /tmp/ccJo4Daw.i -quiet -dumpba
> se junk.cc -Wall -version -o /tmp/ccJo4Daw.s
> GNU C++ version 2.2.2 compiled by GNU C version 2.2.2.
> junk.cc: In function `int main ()':
> junk.cc:4: warning: unused variable `p'
> as -u -o junk.o /tmp/ccJo4Daw.s
> /import/blossom/lib/gcc-lib/rs6000/2.2.2/ld -T512 -H512 -btextro -bhalt:4 -bnod
> elcsect /lib/crt0.o -L/import/blossom/lib/gcc-lib/rs6000/2.2.2 -L/import/blossom
> /lib junk.o -lg++ /import/blossom/lib/gcc-lib/rs6000/2.2.2/libgcc.a -lc /import/
> blossom/lib/gcc-lib/rs6000/2.2.2/libgcc.a
> <masc41>:dougm % a.out
> Virtual memory exceeded in `new'
> <masc41>:dougm % cat junk.cc
> main()
> {
> int x = 0;
> int* p = new int[x];
> }
This is not a bug in gcc. This is the expected behaviour from a call to malloc
with size = 0 in AIX 3.2.
I had a long conversation with some of the IBM folks in Austin, and the
conclusion was that the AIX 3.1.x version of malloc will return a NULL pointer
on malloc(0);, but the Yorktown malloc, the one that is used in AIX 3.2, does
_not_ return a NULL pointer on malloc(0);.
I don't have a copy of the ANSI standard, but in _C:_A_Reference_Manual_,
second edition, by Harbison and Steele, section 18.1, it says:
... If it is impossible for some reason to perform the
requested allocation, or if _size_ is 0, a null pointer
is returned.
Off hand it sounds like the Yorktown malloc (used in AIX 3.2) does not follow
the ANSI standard for malloc. Comments from IBM?
If you wish, you can use the AIX 3.1.x flavor of malloc by setting the
environment variable MALLOCTYPE to 3.1 ("setenv MALLOCTYPE 3.1"). Or, you can
stop trying to allocate zero sized pieces of memory. Or, you can use a different
malloc. The choice, if you decide to accept it, is yours :) Using the AIX 3.1.x
version of malloc takes up a lot more memory, but will get the behaviour you
want.
Cheers,
Tom McConnell
Tom McConnell | Internet: tmcconne@sedona.intel.com
Intel, Corp. C3-21 | Phone: (602)-554-8229
5000 W. Chandler Blvd. | The opinions expressed are my own. No one in
Chandler, AZ 85226 | their right mind would claim them.
Technical Details
Message-ID:
<9208031516.AA27492@thunder>Path:
arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!sedona.intel.com!tmcconneShow Full Headers
Complete Article Headers
Newsgroups: gnu.g++.bug Path: arc1-ca.pugleaf.net!sparky!uunet!cis.ohio-state.edu!sedona.intel.com!tmcconne From: tmcconne@sedona.intel.com (Tom McConnell) Subject: Re: 2.2.2 on rs6000: new[0] - gnu.g++.bug #4579 Message-ID: <9208031516.AA27492@thunder> Sender: gnulists@ai.mit.edu Organization: GNUs Not Usenet Distribution: gnu Date: Mon, 3 Aug 1992 01:16:23 GMT Approved: bug-g++@prep.ai.mit.edu Lines: 74