10081 – basic_ios::_M_cache_locale leaves NULL members in the face of unknown locales (original) (raw)
| Description Pétur Runólfsson 2003-03-14 12:06:00 UTC The constructor basic_ios::basic_ios() doesn't initialize the members _M_fctype, _M_fnumput and _M_fnumget, leading to crashes when these members are accessed later. Release: gcc-3.2.2 Environment: Red Hat Linux 8.0 How-To-Repeat: See attachment. This only checks _M_fctype, to test for the others, numpunct must be specialized for the character type in use. Comment 1 Drea Pinski 2003-05-27 18:47:12 UTC On the mainline (20030527) I get an exception thrown: terminate called after throwing an instance of 'std::bad_cast' what(): St8bad_cast (gdb) bt #0 0x420292d1 in kill () from /lib/i686/libc.so.6 #1 0x420290ba in raise () from /lib/i686/libc.so.6 #2 0x4202a862 in abort () from /lib/i686/libc.so.6 #3 0x400aa4e3 in __gnu_cxx::__verbose_terminate_handler() () at /home/gates/ pinskia/src/gnu/gcc/src/libstdc++-v3/libsupc++/vterminate.cc:96 #4 0x400a8055 in __cxxabiv1::__terminate(void (*)()) (handler=0x400aa3f0 < __gnu_cxx::__verbose_terminate_handler()>) at /home/gates/pinskia/src/gnu/gcc/src/ libstdc++-v3/libsupc++/eh_terminate.cc:43 #5 0x400a8092 in std::terminate() () at /home/gates/pinskia/src/gnu/gcc/src/libstdc++-v3/ libsupc++/eh_terminate.cc:53 #6 0x400a8212 in __cxa_throw (obj=0x400ad2db, tinfo=0x0, dest=0) at /home/gates/ pinskia/src/gnu/gcc/src/libstdc++-v3/libsupc++/eh_throw.cc:80 #7 0x40061c45 in std::__throw_bad_cast() () at typeinfo:138 #8 0x0804a97b in __check_facet<std::ctype<__gnu_cxx_test::pod_char> > (__f=0x0) at localefwd.h:187 #9 0x0804a504 in sentry (this=0xbffec13b, __in=@0xbffec180, __noskipws=false) at istream.tcc:56 #10 0x080494e4 in std::basic_istream<__gnu_cxx_test::pod_char, std::char_traits< __gnu_cxx_test::pod_char> >& std::operator>><__gnu_cxx_test::pod_char, std::char_traits<__gnu_cxx_test::pod_char>, std::allocator<__gnu_cxx_test::pod_char> > (std::basic_istream<__gnu_cxx_test::pod_char, std::char_traits< __gnu_cxx_test::pod_char> >&, std::basic_string<__gnu_cxx_test::pod_char, std::char_traits<__gnu_cxx_test::pod_char>, std::allocator<__gnu_cxx_test::pod_char> > &) (__in=@0xbffec180, __str=@0xbffec170) at istream.tcc:1102 #11 0x0804921a in main () at pr10081.cc:266 Comment 2 Dara Hazeghi 2003-06-08 08:15:25 UTC Confirmed with branch and mainline (20030605). Comment 3 Phil Edwards 2003-06-09 15:21:56 UTC Well, don't say that the members aren't being initialized, because they are: explicit basic_ios(basic_streambuf<_CharT, _Traits>* __sb) : ios_base(), _M_ctype(0), _M_num_put(0), _M_num_get(0) { this->init(__sb); } (The names of the variables were changed mid-May.) The crash is because _M_ctype is still NULL when op>> is executed, leading to a NULL facet argument in __check_facet. basic_ios::init makes an attempt to cache the facet, but since has_facet is (I expect) false for pod_char, the members are not assigned new values. I don't know what the Right Thing is here. Comment 4 Pétur Runólfsson 2003-06-30 11:00:17 UTC Phil Edwards wrote: > Well, don't say that the members aren't being initialized, because > they are: > > explicit > basic_ios(basic_streambuf<_CharT, _Traits>* __sb) > : ios_base(), _M_ctype(0), _M_num_put(0), _M_num_get(0) > { this->init(__sb); } > > (The names of the variables were changed mid-May.) Revision 1.18 of basic_ios.h had this: basic_ios() : ios_base() { } but after this checkin: Fri Mar 28 19:45:44 2003 UTC (2 months, 4 weeks ago) by bkoz=3D20 the constructor reads thus: basic_ios() : ios_base(), _M_fctype(0), _M_fnumput(0), _M_fnumget(0) { } So it seems that the bug has been fixed. > The crash is because _M_ctype is still NULL when op>> is executed, > leading to a NULL facet argument in __check_facet. > basic_ios::init makes an attempt to cache the facet, but since > has_facet is (I expect) false for pod_char, the members are not > assigned new values. > > I don't know what the Right Thing is here. The reason that the test case still crashes is this: operator>>(basic_istream&, basic_string&) calls basic_istream::sentry::sentry() which behaves "as if" it called use_facet<ctype<char_type> >(getloc()). Since the locale returned by getloc() does not contain the requested facet, use_facet throws an exception, and since there is no matching catch block, the program crashes. Wether operator>> or the sentry constructor should catch the exception is the subject of many other bug reports (and DRs). I think this bug can be closed, but a try { [ ... ] } catch (exception) { }=3D20 needs to be added to the testcase if it is added to the testsuite (probably a good idea, since there are currently very few testcases for character types other than char or wchar_t). Regards, Petur Comment 6 Benjamin Kosnik 2003-10-20 22:20:24 UTC Fixed and testecases added on mainline, patched on gcc-3_3-branch. -benjamin Comment 8 Drea Pinski 2003-10-21 15:33:55 UTC Fixed for 3.3.3. | | | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | |