This is the mail archive of the mailing list for the GCC 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]

Re: [libstdc++ PATCH] money_get::do_get subscripts empty string

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.


The problem shows up when running 22_locale/money_get/get/char/ 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.


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