From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 48) id C128C385B52F; Tue, 10 Jan 2023 11:47:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org C128C385B52F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sourceware.org; s=default; t=1673351229; bh=VKXpogsY7tYCa9x53aY4Y8c442lXVggqfreFNPj/OQo=; h=From:To:Subject:Date:In-Reply-To:References:From; b=h5OVqhR9hD0CrXBzBPdbHFZ9iuTjH802QfKiMsbLA3zRJXp7p6eaoQhoLUzndzMMz iijEEfYNB7FNiT3YoPe7WqRC1G2z+bkkbsflIiqlnwS3fSazfeSoNVAjSBuYLWfSM0 nfFYjd7y9JtZGVlWujwpyQvKr0JTat99tkYfm8Tg= From: "vincent-srcware at vinc17 dot net" To: glibc-bugs@sourceware.org Subject: [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros) Date: Tue, 10 Jan 2023 11:47:09 +0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: changed X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: glibc X-Bugzilla-Component: stdio X-Bugzilla-Version: 2.27 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: vincent-srcware at vinc17 dot net X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Resolution: X-Bugzilla-Priority: P2 X-Bugzilla-Assigned-To: unassigned at sourceware dot org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: security- X-Bugzilla-Changed-Fields: Message-ID: In-Reply-To: References: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Bugzilla-URL: http://sourceware.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 List-Id: https://sourceware.org/bugzilla/show_bug.cgi?id=3D23432 --- Comment #1 from Vincent Lef=C3=A8vre --- This bug is still there in glibc 2.36, but this is even worse than what I've said, as some leading zeros are also missing, probably because glibc consid= ers the number of bytes of the string with the thousands separator instead of j= ust the number of digits. Consider the following new testcase: #include #include int main (void) { volatile int m =3D 1234567; volatile long n =3D 1234567890; if (setlocale (LC_ALL, "")) for (int i =3D 0; i < 2; i++) { printf ("%.17d\n", m); printf ("%'.17d\n", m); printf ("%.17ld\n", n); printf ("%'.17ld\n", n); m =3D -m; n =3D -n; } return 0; } zira% LC_ALL=3Den_US.utf8 ./tst 00000000001234567 000000001,234,567 00000001234567890 00001,234,567,890 -00000000001234567 -000000001,234,567 -00000001234567890 -00001,234,567,890 zira% LC_ALL=3Dfr_FR.utf8 ./tst 00000000001234567 00001=E2=80=AF234=E2=80=AF567 00000001234567890 1=E2=80=AF234=E2=80=AF567=E2=80=AF890 -00000000001234567 -00001=E2=80=AF234=E2=80=AF567 -00000001234567890 -1=E2=80=AF234=E2=80=AF567=E2=80=AF890 In the fr_FR.utf8 locale, the space is U+202F NARROW NO-BREAK SPACE, which takes 3 bytes in UTF-8: e2 80 af. This is probably why there are even fewer leading zeros in the output. As this can be seen with this testcase, only the thousands separator is han= dled incorrectly, not the minus sign for the negative numbers (which doesn't aff= ect the number of leading zeros). Note: this might have been partially fixed recently in master (though I couldn't see any mention related to the thousands' grouping character or the width field in the Git log), since a change of behavior triggered a failure= in the GNU MPFR testsuite: https://sympa.inria.fr/sympa/arc/mpfr/2023-01/msg00001.html https://sympa.inria.fr/sympa/arc/mpfr/2023-01/msg00002.html (the "expected" value is actually incorrect as it was based on the incorrect behavior of glibc; so this is currently a bug in the MPFR testsuite). But n= ote that there is still a missing thousands' grouping character. --=20 You are receiving this mail because: You are on the CC list for the bug.=