[libstdc++ PATCH] money_get::do_get subscripts empty string
Doug Gregor
dgregor@apple.com
Mon Jun 30 19:48:00 GMT 2003
On Monday, June 30, 2003, at 12:15 PM, Benjamin Kosnik wrote:
>
>> This patch fixes an unsafe loop in money_get::do_get that invokes
>> undefined behavior when __tmp_units is an empty string (this does
>> occur, and was tripping up the debug mode test runs). Tested on
>> powerpc-apple-darwin6.6; no regressions.
>
> Interesting. Can you show me how this happens? I'm using a slightly
> different vesion of the underlying locale code, so something that is
> making your failure obvious would be appreciated.
>
> -benjamin
The problem shows up when running 22_locale/money_get/get/char/7.cc.
Specifically, the money_get<char,InIt>::get call at line 62 (test
string is "Golgafrincham") results in an empty __temp_units string at
the loop in question.
Note that the debug mode check that catches this is being very picky:
when __temp_units is empty, the expression __temp_units[0] has
undefined behavior according to 21.3.4/1 because __temp_units is
non-const. Granted, libstdc++ actually gives reasonable behavior here
(it returns the terminal character), so the loop is correct if we know
that __ctype.widen('0') can never compare equal to the terminal
character.
Can ctype<_CharT>().widen('0') equal _CharT()? If so, we need this
patch. If not, we need this patch only for debug mode, and I'll submit
a patch that makes debug mode happy without the (minor) efficiency hit.
Doug
More information about the Libstdc++
mailing list