This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
Re: iostream changes locale to format a number
- From: Stephen M.Webb <stephenw at cryptocard dot com>
- To: Paolo Carlini <pcarlini at unitus dot it>
- Cc: libstdc++ at gcc dot gnu dot org
- Date: Fri, 3 May 2002 10:41:01 -0400
- Subject: Re: iostream changes locale to format a number
- References: <3CD27E4D.8010905@unitus.it> <20020503135422454.AAA1328@ns2.goodmedia.com@there> <3CD297FF.7000407@unitus.it>
- Reply-to: stephenw at cryptocard dot com
On May 3, 2002 10:00 am, Paolo Carlini wrote:
>
> Stephen I have tested Takeshi's testcase with today's 3.1 and the
> problem it's there! Of course it's there because __convert_from_v
> it's not ok!
A closer reading of __convert_from_v shows the only thing in between
the set and restore setlocale is a sprintf. I wouldn't expect sprintf
to modify the current locale, but the XPG4 spec is explicitly vague
about the nature of the string returned by setlocale, so it's not out
of the question that sprintf might alter the value at the address
returned by setlocale. This should be easy to confirm (if changing
locales doesn't core on you).
In short, you're right. The only way to be 100% safe is to copy the
string. There are 24 instances of this behaviour throughout the C++
standard library. I'd offer my services but I think I'm looking at a
painful system restore over the next little while....
--
Stephen M. Webb