This is the mail archive of the libstdc++@gcc.gnu.org mailing list for the libstdc++ project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[libstdc++] fix (tricksy, wicked, false) sizeof bug in vterminate.cc


Why yes, I have just seen _The Two Towers_, how did you know?


I was testing a fix to the bitset class which involves the possible
throwing of an exception, and noticed that our new shiny fprintf-less
verbose_terminate() was being far from verbose.  What should have been

    terminate called after throwing an instance of 'std::ios_base::failure'
      what():  basic_ios::clear(iostate) caused exception
    Aborted (core dumped)

was coming up as

    terminate called after throwing an instance of 'std'
      what():  bas
    Aborted (core dumped)


The writestr macro as used in pure.cc (and elsewhere in other libraries)
is fine when used like this:

    #define writestr(str)  write(2, str, sizeof(str) - 1)

    writestr ("pure virtual method called\n");

Is not so good when used like this:

    char* dem = __cxa_demangle(name, 0, 0, &status);

    writestr("terminate called after throwing an instance of '");
    if (status == 0)
        writestr(dem);

Of course, sizeof(char*) is 4.  Oops.  Fixed thusly.



2002-12-26  Phil Edwards  <pme@gcc.gnu.org>

	* libsupc++/vterminate.cc (writestr):  Use __builtin_strlen.


Index: libsupc++/vterminate.cc
===================================================================
RCS file: /cvs/gcc/gcc/libstdc++-v3/libsupc++/vterminate.cc,v
retrieving revision 1.1
diff -u -3 -p -r1.1 vterminate.cc
--- libsupc++/vterminate.cc	26 Dec 2002 06:10:35 -0000	1.1
+++ libsupc++/vterminate.cc	26 Dec 2002 22:25:50 -0000
@@ -35,7 +35,7 @@
 
 #ifdef _GLIBCPP_HAVE_UNISTD_H
 # include <unistd.h>
-# define writestr(str)  write(2, str, sizeof(str) - 1)
+# define writestr(str)  write(2, str, __builtin_strlen(str))
 #else
 # include <cstdio>
 # define writestr(str)  std::fputs(str, stderr)



Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]