Mail Archives: djgpp/1997/10/12/16:49:53
On 10/11/97 12:55:45 AM ao950 wrote:
>Compiling a C++ program I encountered repeated SIGSEGV in __builtin_new.
>The lines causing the problem are
>
>array=new int[_size*2]
>
>and
>
>if (!_next) _next=new BlankListItem
>
>Debugger use showed that _size is a legit value in the former occurrence,
>namely 1, so _size*2 is 2. Array is a local variable of type int *. _size
>is a member of an object and the object came from a pointer, but the
>object exists (pointer is valid) so accessing _size isn't causing it to
seg
>out.
>In the latter case, similarly _next is legitimate, has value NULL, and
>this time there aren't even any arguments to new.
>
>I am forced to conclude that there is a bug in GCC's implementation of
>new, because new is apparently segging out when every input to new is
>legit. I verified that the malloc arena is not being corrupted.
>Specifically, I am nowhere writing arrays out of bounds, everything I new
>I delete, everything I array-new I array-delete, and I'm not leaking core.
>
>Here is a traceback for the latter occurrence:
I think this is a too early conclusion !!
I (tried) compiled your program with DJGPP and Borland C++
but with maximum warnings. DJGPP compiled it but issued some warnings.
BC++ refused to compile it. (ie BC found errors at the same line DJGPP
displayed
warnings)
DJGPP:
gxx groups.cc -Wall -pedantic -o groups.exe
output:
you have the compiler. try and see.
Borland C++ 5.02:
bcc32 -w -w-inl groups.cpp
output:
Borland C++ 5.2 for Win32 Copyright (c) 1993, 1997 Borland International
groups.cpp:
Error groups.h 273: Cannot convert 'int *' to 'int * *' in function
GroupTable::GroupTable(int)
Error groups.h 274: Cannot convert 'BlankListItem * *' to 'BlankListItem *
* *' in function GroupTable::GroupTable(int)
Error groups.h 278: Cannot convert 'BlankListItem *' to 'BlankListItem * *'
in function GroupTable::GroupTable(int)
Error groups.h 292: Cannot convert 'int *' to 'int * *' in function
GroupTable::GroupTable(GroupTable &)
Error groups.h 293: Cannot convert 'BlankListItem * *' to 'BlankListItem *
* *' in function GroupTable::GroupTable(GroupTable &)
Error groups.h 297: Cannot convert 'BlankListItem *' to 'BlankListItem * *'
in function GroupTable::GroupTable(GroupTable &)
See ? there are still errors.
The first error for example is at line:
int** table=new (int *)[order]; // this code is illegal ANSI/ISO C++
You want "order" elements of type (int*).
you can write:
int** table = (int**) ::operator new( order * sizeof(int*)); // this
compiles fine.
dont forget to #include <new.h> and use 'operator delete' to release
memory.
i.e.
::operator delete (table);
Eyal.
- Raw text -