This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
[PATCH] printf("%#f") format specifier bug
- From: Brian Dessent <brian at dessent dot net>
- To: newlib at sourceware dot org
- Date: Thu, 19 Apr 2007 03:15:24 -0700
- Subject: [PATCH] printf("%#f") format specifier bug
- Reply-to: newlib at sourceware dot org
When the 'alternate-form' printf flag (#) is used with floating point
output types, the spec says that a trailing decimal must be output.
However, newlib currently gets this wrong.
I used the tfformat.c testcase from glibc to check this:
<http://sourceware.org/cgi-bin/cvsweb.cgi/~checkout~/libc/stdio-common/tfformat.c?cvsroot=glibc>
Before the patch:
Error in line 593 using "%#6.f". Result is " -0"; should be: "
-0.".
Error in line 746 using "%#4.f". Result is " -0"; should be: " -0.".
Error in line 1269 using "%+#0.f". Result is "-0"; should be: "-0.".
Error in line 1296 using "%#4.f". Result is " -0"; should be: " -0.".
Error in line 1627 using "%+#2.0f". Result is "-0"; should be: "-0.".
Error in line 1993 using "%#6.f". Result is " -0"; should be: "
-0.".
Error in line 2117 using "%+#1.f". Result is "+0"; should be: "+0.".
Error in line 2178 using "%#3.f". Result is " 0"; should be: " 0.".
Error in line 2470 using "%#.0f". Result is "0"; should be: "0.".
Error in line 2848 using "%#.0f". Result is "0"; should be: "0.".
Error in line 3362 using "%#3.f". Result is " 0"; should be: " 0.".
Error in line 3514 using "%#.0f". Result is "0"; should be: "0.".
Error in line 3723 using "%#.0f". Result is "0"; should be: "0.".
Error in line 3754 using "%+#1.f". Result is "+0"; should be: "+0.".
Error in line 3935 using "%#3.f". Result is " 0"; should be: " 0.".
Error in line 4012 using "%.1a". Result is "a"; should be: "0x1.0p+4".
Error in line 4013 using "%.20a". Result is "a"; should be:
"0x1.00000000000000000000p+4".
Encountered 17 errors in 4005 tests.
With the patch, the only errors left are %a (which I believe Eric Blake
has already tackled):
Error in line 4012 using "%.1a". Result is "a"; should be: "0x1.0p+4".
Error in line 4013 using "%.20a". Result is "a"; should be:
"0x1.00000000000000000000p+4".
Encountered 2 errors in 4005 tests.
Brian
2007-04-19 Brian Dessent <brian@dessent.net>
* libc/stdio/vfprintf.c (_vfprintf_r): When the alternate-form flag
has been specified with types 'e', 'E', or 'f', ensure the trailing
decimal is printed.
Index: libc/stdio/vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/stdio/vfprintf.c,v
retrieving revision 1.49
diff -u -p -r1.49 vfprintf.c
--- libc/stdio/vfprintf.c 13 Apr 2007 01:57:33 -0000 1.49
+++ libc/stdio/vfprintf.c 19 Apr 2007 09:38:34 -0000
@@ -1235,7 +1235,7 @@ number: if ((dprec = prec) >= 0)
}
} else if (expt <= 0) {
PRINT ("0", 1);
- if(expt || ndig) {
+ if(expt || ndig || (flags & ALT)) {
PRINT (decimal_point, 1);
PAD (-expt, zeroes);
PRINT (cp, ndig);