c++/2628: Class constructor called when operator new returns null.

pere@hungry.com pere@hungry.com
Tue Apr 24 13:26:00 GMT 2001


>Number:         2628
>Category:       c++
>Synopsis:       Class constructor called when operator new returns null.
>Confidential:   no
>Severity:       critical
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          wrong-code
>Submitter-Id:   net
>Arrival-Date:   Tue Apr 24 13:26:00 PDT 2001
>Closed-Date:
>Last-Modified:
>Originator:     pere@hungry.com
>Release:        gcc-2.95.2
>Organization:
>Environment:
Debian 2.2 (up to date using apt-get upgrade)
>Description:
When running out of memory and operator new returns 0,
the constructor is called with this=0.  This crashes our
application.  To my suprise, adding a prototype for
operator new, with 'throw ()' included, fixes the problem.
I believe the compiled code should be changed to always
check the result from operator new before calling the
object constructor.
>How-To-Repeat:
Compile and run the source to trigger the assert.
>Fix:

>Release-Note:
>Audit-Trail:
>Unformatted:
----gnatsweb-attachment----
Content-Type: text/x-c++src; name="gcc-new-bug.cpp"
Content-Transfer-Encoding: base64
Content-Disposition: attachment; filename="gcc-new-bug.cpp"

LyoKCiAgJSBjKysgLS12ZXJzaW9uCiAgMi45NS4yCiAgJSBjKysgLWZuby1leGNlcHRpb25zIC1v
IGdjYy1uZXctYnVnIGdjYy1uZXctYnVnLmNwcAogICUgLi9nY2MtbmV3LWJ1ZwogIGdjYy1uZXct
YnVnOiBnY2MtbmV3LWJ1Zy5jcHA6MTg6IFRlc3Q6OlRlc3QoKTogQXNzZXJ0aW9uIGB0aGlzJyBm
YWlsZWQuCiAgQWJvcnRlZCAoY29yZSBkdW1wZWQpCiAgJQoKKi8KCiNpbmNsdWRlIDxzdGRsaWIu
aD4KI2luY2x1ZGUgPGFzc2VydC5oPgoKY2xhc3MgVGVzdAp7CnB1YmxpYzoKICBUZXN0KCkgeyBh
c3NlcnQodGhpcyk7IH07Cn07CgovKgogKiBUaGUgZXhpc3RlbmNlIG9mIHRoaXMgcHJvdG90eXBl
IG1ha2UgdGhpcyBwcm9ncmFtIHdvcmsuCiAqLwojaWYgMAp2b2lkICpvcGVyYXRvciBuZXcoc2l6
ZV90IHNpemUpIHRocm93ICgpOwojZW5kaWYKCmludAptYWluKCkKewogIFRlc3QgKnRlc3QgPSBu
ZXcgVGVzdDsKICByZXR1cm4gMDsKfQoKdm9pZCAqCm9wZXJhdG9yIG5ldyhzaXplX3Qgc2l6ZSkK
ICB0aHJvdyAoKQp7CiAgaWYgKHNpemUgPT0gc2l6ZW9mKFRlc3QpKQogICAgcmV0dXJuIDA7CiAg
ZWxzZQogICAgewogICAgICBpZiAoMCA9PSBzaXplKQoJc2l6ZSA9IDE7CiAgICAgIHJldHVybiBt
YWxsb2Moc2l6ZSk7CiAgICB9Cn0KCnZvaWQKb3BlcmF0b3IgZGVsZXRlKHZvaWQgKnB0cikKICB0
aHJvdyAoKQp7CiAgaWYgKDAgPT0gcHRyKQogICAgcmV0dXJuOwoKICBmcmVlKHB0cik7Cn0K



More information about the Gcc-bugs mailing list