This is the mail archive of the
glibc-bugs@sourceware.org
mailing list for the glibc project.
[Bug libc/4342] scanf %lg problem with hex numbers
- From: "jakub at redhat dot com" <sourceware-bugzilla at sourceware dot org>
- To: glibc-bugs at sources dot redhat dot com
- Date: 23 Apr 2007 12:44:47 -0000
- Subject: [Bug libc/4342] scanf %lg problem with hex numbers
- References: <20070410222210.4342.madcoder@debian.org>
- Reply-to: sourceware-bugzilla at sourceware dot org
------- Additional Comments From jakub at redhat dot com 2007-04-23 13:44 -------
That's how *scanf initially worked, till the
1999-08-13 Ulrich Drepper <drepper@cygnus.com>
* stdio-common/tstscanf.c: Add test for hexadecimal float parsing
problem.
* stdio-common/vfscanf.c: Don't recognize hexadecimal floats without
exponent.
--- stdio-common/vfscanf.c 21 Jun 1999 13:35:40 -0000 1.67
+++ stdio-common/vfscanf.c 13 Aug 1999 19:41:26 -0000 1.68
@@ -1410,8 +1410,8 @@ __vfscanf (FILE *s, const char *format,
/* Have we read any character? If we try to read a number
in hexadecimal notation and we have read only the `0x'
- prefix this is an error. */
- if (wpsize == 0 || (is_hexa && wpsize == 2))
+ prefix or no exponent this is an error. */
+ if (wpsize == 0 || (is_hexa && (wpsize == 2 || ! got_e)))
conv_error ();
scan_float:
--- stdio-common/tstscanf.c 6 Jun 1999 09:18:57 -0000 1.12
+++ stdio-common/tstscanf.c 13 Aug 1999 22:39:01 -0000 1.13
@@ -250,5 +250,20 @@ main (int argc, char **argv)
}
}
+ fputs ("Test 8:\n", stdout);
+ {
+ double d = 123456.789;
+ int res;
+
+ res = sscanf ("0x1234", "%lf", &d);
+ printf ("res = %d, d = %f\n", res, d);
+
+ if (res != 0 || d != 123456.789)
+ {
+ fputs ("test failed!\n", stdout);
+ result = 1;
+ }
+ }
+
exit (result);
}
change. My reading of both ISO C99 and current POSIX suggests that indeed
the exponent is only optional. While ISO C99 has a footnote:
"fscanf pushes back at most one input character onto the input stream.
Therefore, some sequences that are acceptable to strtod, strtol, etc., are
unacceptable to fscanf." I don't think this applies here, as the hexadecimal
float exponent part is structured the same as decimal exponent part, just with
a different letter (p vs. e) and as the decimal float has the exponent part
optional, there is no reason why it couldn't be optional even for hexadecimal
floats.
--
http://sourceware.org/bugzilla/show_bug.cgi?id=4342
------- You are receiving this mail because: -------
You are on the CC list for the bug, or are watching someone who is.