From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 27678 invoked by alias); 23 Apr 2007 12:45:01 -0000 Received: (qmail 27027 invoked by uid 48); 23 Apr 2007 12:44:47 -0000 Date: Mon, 23 Apr 2007 12:45:00 -0000 Message-ID: <20070423124447.27026.qmail@sourceware.org> From: "jakub at redhat dot com" To: glibc-bugs@sources.redhat.com In-Reply-To: <20070410222210.4342.madcoder@debian.org> References: <20070410222210.4342.madcoder@debian.org> Reply-To: sourceware-bugzilla@sourceware.org Subject: [Bug libc/4342] scanf %lg problem with hex numbers X-Bugzilla-Reason: CC Mailing-List: contact glibc-bugs-help@sourceware.org; run by ezmlm Precedence: bulk List-Id: List-Subscribe: List-Post: List-Help: , Sender: glibc-bugs-owner@sourceware.org X-SW-Source: 2007-04/txt/msg00094.txt.bz2 ------- 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 * 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.