Hello,
I have noticed, that, while parsing {a float_value immediately followed by 'n' or 'N'} with the "%f%c" format, the sscanf function of cygwin-1.5.16-1 behaves differently from the scanf function of cygwin-1.5.14-1.
Until cygwin-1.5.14-1 (included), 'n' matches %c, while with cygwin-1.5.15-1 and cygwin-1.5-16-1, 'n' is no more assigned to %c.
In the following test case, I would expect the progran to output i=2 x=1 m=a i=2 x=1 m=n
that was the case until cygwin-1.5.14-1 (included).
With cygwin-1.5.15-1 and cygwin-1.5-16-1, the program outputs instead i=2 x=1 m=a i=1 x=1 m=_
Maybe I have been misusing sscanf. Or there is a relationship with the NaN-parsing problem of the "newlib".
Best regards. Jean-Christophe K.
--- beginning of test case --- jck:/sscanf> cat ssn.c #include <stdio.h>
int main() { double x; char m; int i;
x = 0.0; m = '_'; i = sscanf("1.0a", "%lf%c", &x, &m); printf("i=%d x=%g m=%c\n", i, x, m); x = 0.0; m = '_'; i = sscanf("1.0n", "%lf%c", &x, &m); printf("i=%d x=%g m=%c\n", i, x, m); return 0; }
jck:/sscanf> gcc -O0 ssn.c -o ssn.exe jck:/sscanf> ./ssn.exe i=2 x=1 m=a i=1 x=1 m=_ --- end of test case ---
----- Original Message ----- From: "Jeff Johnston" <jjohnstn at redhat dot com>
To: "Dave Korn" <dave dot korn at artimi dot com>
Cc: <cygwin at cygwin dot com>; <newlib at sources dot redhat dot com>
Sent: Tuesday, April 05, 2005 8:47 PM
Subject: Re: RFC: Fix partial NaN-parsing problem [was RE: sscanf problem]
Patch checked in. Thanks.
-- Jeff J.
Dave Korn wrote:----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!>--------------------------- [EMAIL PROTECTED] /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; }
[EMAIL PROTECTED] /test/sscanf> gcc -O0 -g ss.c -o ss.exe [EMAIL PROTECTED] /test/sscanf> ./ss.exe i=0 x=10 i=1 x=NaN [EMAIL PROTECTED] /test/sscanf> ---------------------------<snip!>---------------------------
cheers, DaveK
-- 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/
-- 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/