public inbox for libc-hacker@sourceware.org
 help / color / mirror / Atom feed
From: Jakub Jelinek <jakub@redhat.com>
To: Ulrich Drepper <drepper@redhat.com>
Cc: Glibc hackers <libc-hacker@sources.redhat.com>
Subject: [PATCH] Fix BZ#4070 special case
Date: Fri, 13 Apr 2007 14:20:00 -0000	[thread overview]
Message-ID: <20070413142401.GG1826@sunsite.mff.cuni.cz> (raw)

Hi!

When !info->alt, trailing zeros are removed and decimal point as well.
So for a number which has exponent -5 initially, but rounds to
0.0001, we have L"1.0000..." at wstartp and wcp == wstartp + 1
(as even the decimal point was eaten).  This results either in an assertion
failure or with -DNDEBUG=1 in wmemset with -1L as last argument (thus likely
a segfault).

2007-04-13  Jakub Jelinek  <jakub@redhat.com>

	* stdio-common/printf_fp.c (___printf_fp): Fix exponent -4
	special case handling when wcp == wstartp + 1.  Fix a comment typo.
	* stdio-common/tfformat.c (sprint_doubles): Add a new testcase.

--- libc/stdio-common/printf_fp.c.jj	2007-02-26 18:13:47.000000000 +0100
+++ libc/stdio-common/printf_fp.c	2007-04-13 16:03:38.000000000 +0200
@@ -990,7 +990,7 @@ ___printf_fp (FILE *fp,
 				       0))
 	      /* This is a special case: the rounded number is 1.0,
 		 the format is 'g' or 'G', and the alternative format
-		 is selected.  This means the result mist be "1.".  */
+		 is selected.  This means the result must be "1.".  */
 	      --added_zeros;
 	  }
 
@@ -1081,12 +1081,17 @@ ___printf_fp (FILE *fp,
 	    /* This is another special case.  The exponent of the number is
 	       really smaller than -4, which requires the 'e'/'E' format.
 	       But after rounding the number has an exponent of -4.  */
-	    assert (wcp >= wstartp + 2);
+	    assert (wcp >= wstartp + 1);
 	    assert (wstartp[0] == L'1');
 	    __wmemcpy (wstartp, L"0.0001", 6);
 	    wstartp[1] = decimalwc;
-	    wmemset (wstartp + 6, L'0', wcp - (wstartp + 2));
-	    wcp += 4;
+	    if (wcp >= wstartp + 2)
+	      {
+		wmemset (wstartp + 6, L'0', wcp - (wstartp + 2));
+		wcp += 4;
+	      }
+	    else
+	      wcp += 5;
 	  }
 	else
 	  {
--- libc/stdio-common/tfformat.c.jj	2007-02-26 18:13:47.000000000 +0100
+++ libc/stdio-common/tfformat.c	2007-04-13 15:52:53.000000000 +0200
@@ -4020,6 +4020,7 @@ sprint_double_type sprint_doubles[] =
   {__LINE__, 0.000956,			"0.001", "%#.0g"},
   {__LINE__, 0.000098,			"0.0001", "%#.0g"},
   {__LINE__, 0.0000996,			"0.00010", "%#.2g"},
+  {__LINE__, 9.999999999999999e-05,	"0.0001", "%g"},
 
   {0 }
 

	Jakub

                 reply	other threads:[~2007-04-13 14:20 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20070413142401.GG1826@sunsite.mff.cuni.cz \
    --to=jakub@redhat.com \
    --cc=drepper@redhat.com \
    --cc=libc-hacker@sources.redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).