SEGV fault when using wchar_t streams
Rob Lugt
roblugt@bigfoot.com
Tue Aug 22 03:23:00 GMT 2000
Did anybody else try this out?ÃÂ Is
this the correct group to post bugs to?
ÃÂ
I now have a temporary fix for this.ÃÂ
If I add a line before (5): ÃÂ ÃÂ ÃÂ
5ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ std::wcout.width(1);
ÃÂ
setting the width to 1 prior to outputing
the wchar_t fixes the problem.
ÃÂ
I stumbled on the width fix by stepping
through the code with gdb.ÃÂ I was surprised to see that a line in
bits/ostream.tcc initialising __w was not executed (the debugger jumped over
it).ÃÂ Why would this be?
ÃÂ
ÃÂ template<typename _CharT, typename
_Traits> ÃÂ ÃÂ ÃÂ basic_ostream<_CharT,
_Traits>& ÃÂ ÃÂ ÃÂ operator<<(basic_ostream<_CharT,
_Traits>& __out, _CharT __c) ÃÂ ÃÂ ÃÂ
{ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ typedef basic_ostream<_CharT, _Traits>
__ostream_type; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ __ostream_type::sentry
__cerb(__out); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ if
(__cerb) ÃÂ ÃÂ ÃÂ ÃÂ { ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
try { ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ streamsize __w =
__out.width();ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
<<<<--- debugger jumps over this
line ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ _CharT
__pads[__w]; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ __pads[0] =
__c; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ streamsize __len =
1; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ if (__w >
__len) ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
{ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ _S_pad_char(__out, __pads, &__c, __w,
__len); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ __len =
__w; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
} ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ __out.write(__pads,
__len); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
__out.width(0); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
} ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ catch(exception&
__fail){ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ // 27.6.1.2.1
Common requirements. ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ // Turn
this on without causing an ios::failure to be
thrown. ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
__out.setstate(ios_base::badbit); ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
if ((__out.exceptions() & ios_base::badbit) !=
0) ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ
throw; ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ } ÃÂ ÃÂ ÃÂ ÃÂ
} ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ return __out; ÃÂ ÃÂ ÃÂ
}
ÃÂ
ÃÂ
ÃÂ
>I compile the following program with
./g++ -fhonor-std
>
>ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 1
#include <iostream> >ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 2 int main(int
argc, char* argv[]) >ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 3
{ >ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 4ÃÂ ÃÂ ÃÂ ÃÂ std::wcout
<< L"H"; >ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 5ÃÂ ÃÂ ÃÂ ÃÂ
std::wcout << L'i' << std::ends <<
std::endl;ÃÂ ÃÂ ÃÂ // This appears to be the problem
line >ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 6ÃÂ ÃÂ ÃÂ ÃÂ std::wcout
<< L"This is going to die - bye" <<
std::endl; >ÃÂ ÃÂ ÃÂ ÃÂ ÃÂ 7 } ÃÂ
More information about the Libstdc++
mailing list