This is the mail archive of the
mailing list for the GCC project.
Re: [libstdc++ PATCH] money_get::do_get subscripts empty string
- From: Doug Gregor <dgregor at apple dot com>
- To: Benjamin Kosnik <bkoz at redhat dot com>
- Cc: libstdc++ at gcc dot gnu dot org, gcc-patches at gcc dot gnu dot org
- Date: Mon, 30 Jun 2003 12:48:22 -0700
- Subject: 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/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 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
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.