Problems with __cxa_demangle and the verbose terminate handler

Benjamin Kosnik bkoz@redhat.com
Mon Feb 23 17:32:00 GMT 2004


First, the terminate handler bits.

>In this patch, I've made the verbose terminate handler defensively
>notice recursive calls to "std::terminate".

This is a good idea.

>Perhaps most dangerous of all is this code in vterminate.cc:
>
>  # define writestr(str)  write(2, str, __builtin_strlen(str))
>
>This bit of cleverness is designed to let the terminate handler write
>to the standard error stream.  However, there is no way to know that
>file descriptor 2 *is* the standard error stream.  If the process
>closes stderr, and then opens another file (say, "/dev/launch_missle",
>or "/dev/database") that new file descriptor may very well be
>descriptor 2.  Using "fputs" to write to "stderr" does not have this
>problem.

I have always been in favor of using fputs here, instead of write. The
problem is that some people feel that fputs brings in too much of "C"
library.

As I see it, the solutions are to:

1) use fputs
2) use fileno(stderr) to acertain the file descriptor of stderr, instead of 2

I suggest 1, and have a patch to do so ready.

-benjamin 



More information about the Libstdc++ mailing list