public inbox for glibc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
@ 2023-01-10 11:29 ` vincent-srcware at vinc17 dot net
  2023-01-10 11:47 ` vincent-srcware at vinc17 dot net
                   ` (11 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-10 11:29 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

Vincent Lefèvre <vincent-srcware at vinc17 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|missing thousands separator |incorrect printf output for
                   |in printf output for        |integers with thousands
                   |leading zeros of integers   |separator and precision
                   |                            |field larger than the
                   |                            |number of digits (needing
                   |                            |leading zeros)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
  2023-01-10 11:29 ` [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros) vincent-srcware at vinc17 dot net
@ 2023-01-10 11:47 ` vincent-srcware at vinc17 dot net
  2023-01-10 11:49 ` vincent-srcware at vinc17 dot net
                   ` (10 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-10 11:47 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #1 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
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 considers
the number of bytes of the string with the thousands separator instead of just
the number of digits. Consider the following new testcase:

#include <stdio.h>
#include <locale.h>

int main (void)
{
  volatile int m = 1234567;
  volatile long n = 1234567890;
  if (setlocale (LC_ALL, ""))
    for (int i = 0; i < 2; i++)
      {
        printf ("%.17d\n", m);
        printf ("%'.17d\n", m);
        printf ("%.17ld\n", n);
        printf ("%'.17ld\n", n);
        m = -m;
        n = -n;
      }
  return 0;
}

zira% LC_ALL=en_US.utf8 ./tst
00000000001234567
000000001,234,567
00000001234567890
00001,234,567,890
-00000000001234567
-000000001,234,567
-00000001234567890
-00001,234,567,890

zira% LC_ALL=fr_FR.utf8 ./tst
00000000001234567
00001 234 567
00000001234567890
1 234 567 890
-00000000001234567
-00001 234 567
-00000001234567890
-1 234 567 890

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 handled
incorrectly, not the minus sign for the negative numbers (which doesn't affect
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 note
that there is still a missing thousands' grouping character.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
  2023-01-10 11:29 ` [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros) vincent-srcware at vinc17 dot net
  2023-01-10 11:47 ` vincent-srcware at vinc17 dot net
@ 2023-01-10 11:49 ` vincent-srcware at vinc17 dot net
  2023-01-10 12:07 ` [Bug stdio/23432] incorrect printf output " vincent-srcware at vinc17 dot net
                   ` (9 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-10 11:49 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #2 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
(In reply to Vincent Lefèvre from comment #1)
> 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), [...]

I actually meant "precision field" (I did a search on "precision").

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (2 preceding siblings ...)
  2023-01-10 11:49 ` vincent-srcware at vinc17 dot net
@ 2023-01-10 12:07 ` vincent-srcware at vinc17 dot net
  2023-01-10 12:23 ` [Bug stdio/23432] incorrect printf output for integers " vincent-srcware at vinc17 dot net
                   ` (8 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-10 12:07 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

Vincent Lefèvre <vincent-srcware at vinc17 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|incorrect printf output for |incorrect printf output
                   |integers with thousands     |with thousands separator
                   |separator and precision     |and precision field larger
                   |field larger than the       |than the number of digits
                   |number of digits (needing   |(needing leading zeros)
                   |leading zeros)              |

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (3 preceding siblings ...)
  2023-01-10 12:07 ` [Bug stdio/23432] incorrect printf output " vincent-srcware at vinc17 dot net
@ 2023-01-10 12:23 ` vincent-srcware at vinc17 dot net
  2023-01-10 12:32 ` vincent-srcware at vinc17 dot net
                   ` (7 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-10 12:23 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

Vincent Lefèvre <vincent-srcware at vinc17 dot net> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|incorrect printf output     |incorrect printf output for
                   |with thousands separator    |integers with thousands
                   |and precision field larger  |separator and precision
                   |than the number of digits   |field larger than the
                   |(needing leading zeros)     |number of digits (needing
                   |                            |leading zeros)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (4 preceding siblings ...)
  2023-01-10 12:23 ` [Bug stdio/23432] incorrect printf output for integers " vincent-srcware at vinc17 dot net
@ 2023-01-10 12:32 ` vincent-srcware at vinc17 dot net
  2023-01-17 12:15 ` schwab@linux-m68k.org
                   ` (6 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-10 12:32 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #3 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
Note: This concerns only integers (e.g. %d), as with floating-point numbers,
specifying a precision cannot yield leading zeros. The POSIX rule is different
with zero padding ("If the '0' and <apostrophe> flags both appear, the grouping
characters are inserted before zero padding."), which is due to the width field
rather than the precision field.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (5 preceding siblings ...)
  2023-01-10 12:32 ` vincent-srcware at vinc17 dot net
@ 2023-01-17 12:15 ` schwab@linux-m68k.org
  2023-01-17 12:51 ` vincent-srcware at vinc17 dot net
                   ` (5 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: schwab@linux-m68k.org @ 2023-01-17 12:15 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #4 from Andreas Schwab <schwab@linux-m68k.org> ---
> https://sympa.inria.fr/sympa/arc/mpfr/2023-01/msg00001.html
> https://sympa.inria.fr/sympa/arc/mpfr/2023-01/msg00002.html

These links no longer work (infinite redirection).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (6 preceding siblings ...)
  2023-01-17 12:15 ` schwab@linux-m68k.org
@ 2023-01-17 12:51 ` vincent-srcware at vinc17 dot net
  2023-01-17 13:32 ` schwab@linux-m68k.org
                   ` (4 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-01-17 12:51 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #5 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
(In reply to Andreas Schwab from comment #4)
> > https://sympa.inria.fr/sympa/arc/mpfr/2023-01/msg00001.html
> > https://sympa.inria.fr/sympa/arc/mpfr/2023-01/msg00002.html
> 
> These links no longer work (infinite redirection).

I don't have any issue with the Firefox and Opera web browsers. I suggest to
remove cookies associated with the inria.fr domain (obsolete cookies can
sometimes yield strange behavior).

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (7 preceding siblings ...)
  2023-01-17 12:51 ` vincent-srcware at vinc17 dot net
@ 2023-01-17 13:32 ` schwab@linux-m68k.org
  2023-02-02  1:22 ` vincent-srcware at vinc17 dot net
                   ` (3 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: schwab@linux-m68k.org @ 2023-01-17 13:32 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #6 from Andreas Schwab <schwab@linux-m68k.org> ---
I don't have any cookies.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (8 preceding siblings ...)
  2023-01-17 13:32 ` schwab@linux-m68k.org
@ 2023-02-02  1:22 ` vincent-srcware at vinc17 dot net
  2023-02-06 13:58 ` vincent-srcware at vinc17 dot net
                   ` (2 subsequent siblings)
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-02-02  1:22 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #7 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
Though I fixed the MPFR testsuite, there's still a failure due to a new bug in
glibc from git and 2.37. See bug 30068 (which I've just reported) for this new
bug.

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (9 preceding siblings ...)
  2023-02-02  1:22 ` vincent-srcware at vinc17 dot net
@ 2023-02-06 13:58 ` vincent-srcware at vinc17 dot net
  2023-02-06 15:21 ` cvs-commit at gcc dot gnu.org
  2023-02-08  1:12 ` cvs-commit at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: vincent-srcware at vinc17 dot net @ 2023-02-06 13:58 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #8 from Vincent Lefèvre <vincent-srcware at vinc17 dot net> ---
Note that I was wrong in my initial bug report. For

  printf ("%'.17d\n", 123456789);

I said that it should output "000,000,123,456,789". Actually, there were 2
issues in the glibc 2.36- behavior: the missing thousands' grouping characters
with the leading zeros and the incorrect number of digits (15 instead of 17).
So the correct output should be "00,000,000,123,456,789".

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (10 preceding siblings ...)
  2023-02-06 13:58 ` vincent-srcware at vinc17 dot net
@ 2023-02-06 15:21 ` cvs-commit at gcc dot gnu.org
  2023-02-08  1:12 ` cvs-commit at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-06 15:21 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #9 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Carlos O'Donell <carlos@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=c980549cc6a1c03c23cc2fe3e7b0fe626a0364b0

commit c980549cc6a1c03c23cc2fe3e7b0fe626a0364b0
Author: Carlos O'Donell <carlos@redhat.com>
Date:   Thu Jan 19 12:50:20 2023 +0100

    Account for grouping in printf width (bug 30068)

    This is a partial fix for mishandling of grouping when formatting
    integers.  It properly computes the width in the presence of grouping
    characters when the width is larger than the number of significant
    digits. The precision related issue is documented in bug 23432.

    Co-authored-by: Andreas Schwab <schwab@suse.de>

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros)
       [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
                   ` (11 preceding siblings ...)
  2023-02-06 15:21 ` cvs-commit at gcc dot gnu.org
@ 2023-02-08  1:12 ` cvs-commit at gcc dot gnu.org
  12 siblings, 0 replies; 13+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2023-02-08  1:12 UTC (permalink / raw)
  To: glibc-bugs

https://sourceware.org/bugzilla/show_bug.cgi?id=23432

--- Comment #10 from cvs-commit at gcc dot gnu.org <cvs-commit at gcc dot gnu.org> ---
The release/2.37/master branch has been updated by Carlos O'Donell
<carlos@sourceware.org>:

https://sourceware.org/git/gitweb.cgi?p=glibc.git;h=07b9521fc6369d000216b96562ff7c0ed32a16c4

commit 07b9521fc6369d000216b96562ff7c0ed32a16c4
Author: Carlos O'Donell <carlos@redhat.com>
Date:   Thu Jan 19 12:50:20 2023 +0100

    Account for grouping in printf width (bug 30068)

    This is a partial fix for mishandling of grouping when formatting
    integers.  It properly computes the width in the presence of grouping
    characters when the width is larger than the number of significant
    digits. The precision related issue is documented in bug 23432.

    Co-authored-by: Andreas Schwab <schwab@suse.de>
    (cherry picked from commit c980549cc6a1c03c23cc2fe3e7b0fe626a0364b0)

-- 
You are receiving this mail because:
You are on the CC list for the bug.

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2023-02-08  1:12 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <bug-23432-131@http.sourceware.org/bugzilla/>
2023-01-10 11:29 ` [Bug stdio/23432] incorrect printf output for integers with thousands separator and precision field larger than the number of digits (needing leading zeros) vincent-srcware at vinc17 dot net
2023-01-10 11:47 ` vincent-srcware at vinc17 dot net
2023-01-10 11:49 ` vincent-srcware at vinc17 dot net
2023-01-10 12:07 ` [Bug stdio/23432] incorrect printf output " vincent-srcware at vinc17 dot net
2023-01-10 12:23 ` [Bug stdio/23432] incorrect printf output for integers " vincent-srcware at vinc17 dot net
2023-01-10 12:32 ` vincent-srcware at vinc17 dot net
2023-01-17 12:15 ` schwab@linux-m68k.org
2023-01-17 12:51 ` vincent-srcware at vinc17 dot net
2023-01-17 13:32 ` schwab@linux-m68k.org
2023-02-02  1:22 ` vincent-srcware at vinc17 dot net
2023-02-06 13:58 ` vincent-srcware at vinc17 dot net
2023-02-06 15:21 ` cvs-commit at gcc dot gnu.org
2023-02-08  1:12 ` cvs-commit at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).