This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c++/13215] New: bad code generated to call operator new[] when -fcheck-new
- From: "tom at storagematrix dot com" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 28 Nov 2003 11:51:43 -0000
- Subject: [Bug c++/13215] New: bad code generated to call operator new[] when -fcheck-new
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
The code generated to call operator new[] causes a segmentation fault
when operator new[] returns 0 to indicate memory exhaustion.
The code generated by GCC that calls operator new[] (with -fcheck-new)
increments the memory pointer returned by operator new[] by 4 *before*
comparing it to 0 to see if it should call the ctor. The segmentation
fault occurs when the constructor is called.
---- sample.cpp ----
// g++ -g -fcheck-new -fno-exceptions sample.cpp -o sample
#include <stdlib.h>
class foo {
public:
int v;
foo(){ v = 0; }
~foo() {}
void* operator new[](size_t size) {
return 0; // simulated memory failure
}
void operator delete[](void* p, size_t size) { }
};
main()
{
foo *p = new foo[2];
if (p) delete [] p;
return 0;
}
---- EOF ----
How-To-Repeat:
$ g++ -fcheck-new -fno-exceptions sample.cpp -o sample
$ ./sample
Segmentation fault
--
Summary: bad code generated to call operator new[] when -fcheck-
new
Product: gcc
Version: 3.2.2
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: c++
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: tom at storagematrix dot com
CC: gcc-bugs at gcc dot gnu dot org
GCC build triplet: i386-redhat-linux
GCC host triplet: i386-redhat-linux
GCC target triplet: i386-redhat-linux
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=13215