NetBSD Problem Report #60886
From kre@munnari.OZ.AU Thu Oct 15 18:06:33 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 4A1991A923B
for <gnats-bugs@gnats.NetBSD.org>; Thu, 15 Oct 2026 18:06:33 +0000 (UTC)
Message-Id: <202610151805.69FI5aCZ020989@jacaranda.noi.kre.to>
Date: Fri, 16 Oct 2026 01:05:36 +0700 (+07)
From: kre@munnari.OZ.AU
To: gnats-bugs@NetBSD.org
Subject: printf(3) in very obscure situations can incorrectly handle the ' flag
X-Send-Pr-Version: 3.95
X-From4GNATS: "kre@munnari.OZ.AU via gnats" <gnats-admin@NetBSD.org>
>Number: 60886
>Category: lib
>Synopsis: printf(3) in very obscure situations can incorrectly handle the ' flag
>Confidential: no
>Severity: non-critical
>Priority: low
>Responsible: kre
>State: open
>Class: sw-bug
>Submitter-Id: net
>Arrival-Date: Thu Oct 15 18:10:00 +0000 2026
>Last-Modified: Thu Oct 15 18:30:02 +0000 2026
>Originator: Robert Elz
>Release: NetBSD everything
>Organization:
Apostrophes for Flags.
>Environment:
[Irrelevant]
>Description:
In a locale which specifies "thousands" grouping, where the
first (rightmost) "thousands" group separator is to be inserted
between the penultimate and final digits, and if the value being
printed is an integer (not floats, I believe) with a value
between LONG_MAX and ULONG_MAX or between INTMAX_MAX and UINTMAX_MAX
and a printf %'d or %'u format (other flags, field width, precision
etc are all irrelevant) then that rightmost grouping character will
be inserted before, rather than after, the penultimate digit.
And yes, it really requires that specific a set of circumstances
for the bug to manifest,
>How-To-Repeat:
UTSL. This was discovered that way, the chances it will be
seen in the wild are approximately 0 as all real locales (anything
anyone ever uses) either don't do grouping at all, or group every
3 characters (real "thousands") and so fail to meet the pre-reqs
for the bug.
Once my new locales and updated src/tests/lib/libc/t_sprintf test
are committed, that test should fail the sprintf test case for
the new locale which was created specifically to trigger this bug.
I say "should fail" as it works for me, as I have had the fix for
this bug in my tree since before the test was written. I won't
commit in that order however, I will commit the test, and the locales
first, and allow the test to fail (if it doesn't, I need to revisit
how the code works, and see why!)
nb: while this is in an area related to the PR 60496 fixes for
multi-byte decimal points and thousands separators, the bug is
not at all related to that, and has been present for a long time.
>Fix:
Just be patient...
>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 18:13:00 +0000
Responsible-Changed-Why:
I am looking into this PR
From: Robert Elz <kre@munnari.OZ.AU>
To: gnats-bugs@netbsd.org
Cc: netbsd-bugs@netbsd.org
Subject: Re: lib/60886: printf(3) in very obscure situations can incorrectly handle the ' flag
Date: Fri, 16 Oct 2026 01:24:47 +0700
I may have the effect of this bug (when it happens) incorrect.
When I think about it, it is more likely to simply not do
grouping at all when it occurs, rather than to do it incorrectly
(which is still wrong) - as I implied, I have never actually
seen the bug occur (yet) - my printf(3) code was fixed before
I created a locale which could trigger the issue.
In any case, this is truly a very obscure problem, and I don't
plan on requesting pullups to anything when it is fixed, released
versions of NetBSD have no locales which can trigger the problem.
kre
>Unformatted:
(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.