public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/13215] New: bad code generated to call operator new[] when -fcheck-new
@ 2003-11-28 11:51 tom at storagematrix dot com
  2003-11-28 13:14 ` [Bug c++/13215] " falk at debian dot org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: tom at storagematrix dot com @ 2003-11-28 11:51 UTC (permalink / raw)
  To: gcc-bugs

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


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2005-02-15 17:44 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2003-11-28 11:51 [Bug c++/13215] New: bad code generated to call operator new[] when -fcheck-new tom at storagematrix dot com
2003-11-28 13:14 ` [Bug c++/13215] " falk at debian dot org
2003-11-28 17:34 ` [Bug c++/13215] [3.3 only] " pinskia at gcc dot gnu dot org
2003-12-01  2:06 ` [Bug c++/13215] [3.3 Regression] " pinskia at gcc dot gnu dot org
2003-12-21 21:47 ` pinskia at gcc dot gnu dot org
2003-12-21 21:47 ` pinskia at gcc dot gnu dot org
2003-12-21 21:52 ` pinskia at gcc dot gnu dot org
2003-12-22  5:33 ` mmitchel at gcc dot gnu dot org
2003-12-22  5:46 ` gdr at integrable-solutions dot net
2003-12-22 22:57 ` pinskia at gcc dot gnu dot org
2005-02-15 22:22 ` pinskia at gcc dot gnu dot org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).