Abort in low memory situations
Shawn T . Amundson
amundson@gimp.org
Wed Apr 21 11:38:00 GMT 1999
A C++ program compiled with egcs aborts or gets a segmentation
fault when it can no longer allocate memory instead of properly
throwing the exception. Here is my test case (foo.ii):
# 1 "foo.cc"
int
main (int argc, char **argv)
{
try {
while (new char)
;
}
catch (...) {
return 23;
}
return 0;
}
I compiled this using:
g++ --save-temps -o foo foo.cc
The output is usually:
% ./foo
Abort
When I change the "new char" to "new char[2048]", I occasionally
get a segmentation fault instead of an abort. Sometimes it works
as I expect for large memory allocations, I assume because enough
memory is left for the program to throw the exception.
The system is a fairly up-to-date Debian system:
amundson@ariadne % uname -a
Linux ariadne 2.2.5 #2 SMP Fri Apr 9 12:17:19 CDT 1999 i686 unknown
amundson@ariadne % as --version
GNU assembler 2.9.1
amundson@ariadne % g++ --version
egcs-2.91.63
amundson@ariadne % ldd foo
/lib/nfslock.so.0 => /lib/nfslock.so.0 (0x40016000)
libc.so.6 => /lib/libc.so.6 (0x4001f000)
/lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
amundson@ariadne % ls -l /lib/libc.so.6
lrwxrwxrwx 1 root root 13 Apr 7 20:10 /lib/libc.so.6 -> libc-2.1.1.so*
Thanks for any help,
-Shawn
--
Shawn T. Amundson
amundson@gimp.org http://www.gimp.org/~amundson
"The assumption that the universe looks the same in every
direction is clearly not true in reality." - Stephen Hawking
More information about the Gcc-bugs
mailing list