NetBSD Problem Report #60885

From kre@munnari.OZ.AU  Thu Oct 15 17:38:09 2026
Return-Path: <kre@munnari.OZ.AU>
Received: from mail.netbsd.org (mail.netbsd.org [199.233.217.200])
	(using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)
	 key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256
	 client-signature RSA-PSS (2048 bits) client-digest SHA256)
	(Client CN "mail.netbsd.org", Issuer "YR1" (not verified))
	by mollari.NetBSD.org (Postfix) with ESMTPS id 7E7691A923B
	for <gnats-bugs@gnats.NetBSD.org>; Thu, 15 Oct 2026 17:38:09 +0000 (UTC)
Message-Id: <202610151737.69FHb2FN023005@jacaranda.noi.kre.to>
Date: Fri, 16 Oct 2026 00:37:02 +0700 (+07)
From: kre@munnari.OZ.AU
To: gnats-bugs@NetBSD.org
Subject: The scanf() family cannot deal with multi-byte decimal points
X-Send-Pr-Version: 3.95
X-From4GNATS: "kre@munnari.OZ.AU via gnats" <gnats-admin@NetBSD.org>

>Number:         60885
>Category:       lib
>Synopsis:       The scanf() family cannot deal with multi-byte decimal points
>Confidential:   no
>Severity:       serious
>Priority:       high
>Responsible:    kre
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Oct 15 17:40:00 +0000 2026
>Last-Modified:  Thu Oct 15 17:41:11 +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.

>Release-Note:

>Audit-Trail:

Responsible-Changed-From-To: lib-bug-people->kre
Responsible-Changed-By: kre@NetBSD.org
Responsible-Changed-When: Thu, 15 Oct 2026 17:41:11 +0000
Responsible-Changed-Why:
I am looking into this PR


>Unformatted:

NetBSD Home
NetBSD PR Database Search

(Contact us) $NetBSD: query-full-pr,v 1.51 2026/08/10 02:28:17 riastradh Exp $
$NetBSD: gnats_config.sh,v 1.10 2026/05/13 22:00:09 riastradh Exp $
Copyright © 1994-2026 The NetBSD Foundation, Inc. ALL RIGHTS RESERVED.