libstdc++/9870: ctype<wchar_t>::do_widen(char) is broken

jon@biggar.org jon@biggar.org
Thu Feb 27 03:36:00 GMT 2003


>Number:         9870
>Category:       libstdc++
>Synopsis:       ctype<wchar_t>::do_widen(char) is broken
>Confidential:   no
>Severity:       serious
>Priority:       medium
>Responsible:    unassigned
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Feb 27 03:36:00 UTC 2003
>Closed-Date:
>Last-Modified:
>Originator:     Jonathan Biggar
>Release:        gcc 3.2
>Organization:
>Environment:

>Description:
The current implementation of ctype<wchar_t>::do_widen(char)
is broken, because it uses btowc.  The glibc man page for
btowc already states that this function should never be used
because it doesn't handle stateful or multibyte character
encodings well.

Also, since btowc takes an int argument, calling it with a
char value on machines that use signed char improperly sign
extends the argument, which causes an incorrect result to
be returned.

For example, calling do_widen(0xFF) in an ISO8859-1 locale
returns -1, rather than the correct 0xFF.
>How-To-Repeat:
call do_widen() with a signed char value between 0x80 and
0xFF.
>Fix:
do_widen(char) should use mbsrtowcs, like the array based
version does.
>Release-Note:
>Audit-Trail:
>Unformatted:



More information about the Gcc-bugs mailing list