basic_ostringstream<unsigned short> causes segmentation faults

Mads mki@maconomy.dk
Wed Apr 24 03:30:00 GMT 2002


Hello,

does it make sense to use std::basic_ostringstream<unsigned short>?

According to the headerfiles a basic_stringstream has a generic template -
but template specializations are used for char and wchar_t.

As the following example shows we get segmentation faults when the generic
template is used. Defining a char_trait gives the same bug. It seems like
the pure virtual method do_widen in std::__ctype_abstract_base is called...

Is it a bug, an unsupported feature, or a "then don't"?

TIA,
Mads



$ cat slam.cpp
#include <sstream>
int main()
{
        std::basic_ostringstream<unsigned short> x;
}
$ g++ slam.cpp -o slam -g
$ gdb slam
GNU gdb 5.1
Copyright 2001 Free Software Foundation, Inc.
GDB is free software, covered by the GNU General Public License, and you are
welcome to change it and/or distribute copies of it under certain
conditions.
Type "show copying" to see the conditions.
There is absolutely no warranty for GDB.  Type "show warranty" for details.
This GDB was configured as "i686-pc-linux-gnu"...
(gdb) r
Starting program: /home/pmb/tmp/slam

Program received signal SIGSEGV, Segmentation fault.
0x0804a0ea in std::__ctype_abstract_base<unsigned short>::widen(char) const
(this=0x804df6c, __c=32)
    at /home/mk/gcc/include/g++-v3/bits/locale_facets.h:97
97            { return this->do_widen(__c); }
(gdb) where
#0  0x0804a0ea in std::__ctype_abstract_base<unsigned short>::widen(char)
const (this=0x804df6c, __c=32)
    at /home/mk/gcc/include/g++-v3/bits/locale_facets.h:97
#1  0x08049c7f in std::basic_ios<unsigned short, std::char_traits<unsigned
short> >::widen(char) const (
    this=0xbffffa14, __c=32 ' ') at
/home/mk/gcc/include/g++-v3/bits/basic_ios.tcc:99
#2  0x08049934 in std::basic_ios<unsigned short, std::char_traits<unsigned
short> >::init(std::basic_streambuf<unsigned short,
std::char_traits<unsigned short> >*) (this=0xbffffa14, __sb=0x0)
    at /home/mk/gcc/include/g++-v3/bits/basic_ios.tcc:122
#3  0x080496e4 in std::basic_ostream<unsigned short,
std::char_traits<unsigned short>
>::basic_ostream(std::basic_streambuf<unsigned short,
std::char_traits<unsigned short> >*) (this=0xbffff9c0, __vtt_parm=0x804dd48,
__sb=0x0)
    at /home/mk/gcc/include/g++-v3/bits/std_ostream.h:67
#4  0x0804948f in std::basic_ostringstream<unsigned short,
std::char_traits<unsigned short>, std::allocator<unsigned short>
>::basic_ostringstream(std::_Ios_Openmode) (this=0xbffff9c0, __mode=16)
    at /home/mk/gcc/include/g++-v3/bits/std_sstream.h:276
#5  0x080492fd in main () at slam.cpp:5
#6  0x400b79cb in __libc_start_main (main=0x80492e0 <main>, argc=1,
argv=0xbffffaf4, init=0x804900c <_init>,
    fini=0x804caec <_fini>, rtld_fini=0x4000ae60 <_dl_fini>,
stack_end=0xbffffaec)
    at ../sysdeps/generic/libc-start.c:92
(gdb) l
92            tolower(char_type* __lo, const char_type* __hi) const
93            { return this->do_tolower(__lo, __hi); }
94
95            char_type
96            widen(char __c) const
97            { return this->do_widen(__c); }
98
99            const char*
100           widen(const char* __lo, const char* __hi, char_type* __to)
const
101           { return this->do_widen(__lo, __hi, __to); }
(gdb) The program is running.  Exit anyway? (y or n) y
$ g++ -v
Reading specs from /home/mk/gcc/lib/gcc-lib/i686-pc-linux-gnu/3.0.4/specs
Configured with: ../gcc-3.0.4/configure  : (reconfigured)
../gcc-3.0.4/configure --prefix=/home/mk/gcc
Thread model: single
gcc version 3.0.4
$



More information about the Libstdc++ mailing list