NetBSD-Bugs archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
lib/60885: The scanf() family cannot deal with multi-byte decimal points
>Number: 60885
>Category: lib
>Synopsis: The scanf() family cannot deal with multi-byte decimal points
>Confidential: no
>Severity: serious
>Priority: high
>Responsible: lib-bug-people
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 15 17:40:00 +0000 2026
>Originator: Robert Elz
>Release: NetBSD everything
>Organization:
Guild of Impressive Points.
>Environment:
[Irrelevant]
>Description:
strtod() has no problem dealing with multi-byte decimal point
characters, and the code for scanf says:
/* scan a floating point number as if by strtod */
[ @ src/lib/libc/stdio/vfwscanf.c:724 ]
Yet it doesn't.
>How-To-Repeat:
Just read the source:
Just after the comment above is:
if ((width = parsefloat(fp, buf, buf + width, loc)) == 0)
goto match_failure;
Then in parsefloat() (same file) we see:
wchar_t decpt = (wchar_t)(unsigned char)*localeconv_l(loc)->decimal_point;
Duh!
Everything is being processed using wchar_t and it makes one that way.
Really!
Alternately, to see this happen run the not-yet committed updated
tests/lib/libc/locale/t_sprintf
ATF test, which uses an also not-yet committed locale that has
a multi-byte decimal point character, and watch the sscanf
test case fail converting doubles for that locale, whereas
the strto test case, which does the exact same conversion,
on the exact same input, just using strtod() (for this test)
succeeds without issues. (The locale(s), and the updated ATF
test will be committed fairly soon now.)
>Fix:
Use the charset conversion functions (->wchar_t) the way they are
intended to be used, bearing in mind the POSIX restriction that
those with internal state may not be called from any other libc
function (such as this one) (or at least must act as if they aren't).
So, use mbrtowc() with a non-null ps arg.
Home |
Main Index |
Thread Index |
Old Index