delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2005/04/04/14:35:25

Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
From: "Dave Korn" <dave DOT korn AT artimi DOT com>
To: <cygwin AT cygwin DOT com>
Cc: <newlib AT sources DOT redhat DOT com>
Subject: RFC: Fix partial NaN-parsing problem [was RE: sscanf problem]
Date: Mon, 4 Apr 2005 19:35:02 +0100
MIME-Version: 1.0
In-Reply-To: <SERRANO66UDeuXqq5z200000038@SERRANO.CAM.ARTIMI.COM>
Message-ID: <SERRANOcgrjrWReytkX0000003a@SERRANO.CAM.ARTIMI.COM>
X-OriginalArrivalTime: 04 Apr 2005 18:35:07.0923 (UTC) FILETIME=[06C81630:01C53945]
Note-from-DJ: This may be spam

------=_NextPart_000_017E_01C5394D.6548EBF0
Content-Type: text/plain;
	charset="us-ascii"
Content-Transfer-Encoding: 7bit

----Original Message----
>From: Dave Korn
>Sent: 04 April 2005 19:07

> ----Original Message----
>> From: Dave Korn
>> Sent: 04 April 2005 18:51
> 
>> ----Original Message----
>>> From: Michael Hines
>>> Sent: 04 April 2005 19:43
>> 
>>> The following program prints
>>> i=1 x=0
>>> instead of
>>> i=0 x=10
>>> when using the latest version of cygwin1.dll.

>   No, hang on, on checking the newlib-l archive that seems to have been
> something to do with a zero exponent.  This is a separate bug: it accepts
> the first one or two characters of 'nan' and says "ok, everything's still
> good", and then because it's reached the end of the string it treats that
> as a successful parse; it forgets to verify that it doesn't have an
> outstanding half-formed NaN.  I'll post a (provisional) patch shortly.

  Ok, this is only provisional, because as I point out I'm not quite sure
about the corner case where we've refilled the buffer.  It also has minor
formatting issues (slightly long lines in the comment, IMO).  However, it
fixes the testcase, and I've got to go home for the evening, so here's my
work-in-progress; comments welcomed.

---------------------------<snip!>---------------------------
dk AT mace /test/sscanf> cat ss.c

#include <stdio.h>
int main() {
         int i;
         double x;
         x = 10;
         i = sscanf("n", "%lf", &x);
         printf("i=%d x=%g\n", i, x);
         i = sscanf("nan", "%lf", &x);
         printf("i=%d x=%g\n", i, x);
         return 0;
}



dk AT mace /test/sscanf> gcc -O0 -g ss.c -o ss.exe
dk AT mace /test/sscanf> ./ss.exe
i=0 x=10
i=1 x=NaN
dk AT mace /test/sscanf>
---------------------------<snip!>---------------------------





    cheers,
      DaveK
-- 
Can't think of a witty .sigline today....

------=_NextPart_000_017E_01C5394D.6548EBF0
Content-Type: application/octet-stream;
	name="newlib-sscanf-nan-bug-patch.diff"
Content-Transfer-Encoding: quoted-printable
Content-Disposition: attachment;
	filename="newlib-sscanf-nan-bug-patch.diff"

? fix-clip-bug.diff
? newlib-sscanf-nan-bug-patch.diff
Index: newlib/libc/stdio/vfscanf.c
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D
RCS file: /cvs/src/src/newlib/libc/stdio/vfscanf.c,v
retrieving revision 1.28
diff -p -u -r1.28 vfscanf.c
--- newlib/libc/stdio/vfscanf.c	8 Feb 2005 01:33:17 -0000	1.28
+++ newlib/libc/stdio/vfscanf.c	4 Apr 2005 18:31:32 -0000
@@ -1111,7 +1111,23 @@ _DEFUN(__SVFSCANF_R, (rptr, fp, fmt0, ap
 	    }
 	  if (zeroes)
 	    flags &=3D ~NDIGITS;
-	  /*
+      /* We may have a 'N' or possibly even a 'Na' as the start of 'NaN', =
only
+      to run out of chars before it was complete (or having encountered a =
non-
+      matching char).  So check here if we have an outstanding nancount, a=
nd if
+      so put back the chars we did swallow and treat as a failed match. */
+      if (nancount && nancount !=3D 3)
+      {
+          /* Ok... what are we supposed to do in the event that the
+          __srefill call above was triggered in the middle of the partial
+          'NaN' and so we can't put it all back? */
+          while (nancount-- && (p > buf))
+          {
+              ungetc (*(u_char *)--p, fp);
+              --nread;
+          }
+          goto match_failure;
+      }
+      /*
 	   * If no digits, might be missing exponent digits
 	   * (just give back the exponent) or might be missing
 	   * regular digits, but had sign and/or decimal point.


------=_NextPart_000_017E_01C5394D.6548EBF0
Content-Type: text/plain; charset=us-ascii

--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/
------=_NextPart_000_017E_01C5394D.6548EBF0--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019