This is the mail archive of the
newlib@sourceware.org
mailing list for the newlib project.
Re: sprintf bugs with floating point and field specifiers?
- From: Jeff Johnston <jjohnstn at redhat dot com>
- To: Dave Korn <dave dot korn at artimi dot com>
- Cc: "'Matt Lee'" <reachmatt dot lee at gmail dot com>, newlib at sources dot redhat dot com
- Date: Wed, 06 Sep 2006 14:09:22 -0400
- Subject: Re: sprintf bugs with floating point and field specifiers?
- References: <00b901c6d197$25d571d0$a501a8c0@CAM.ARTIMI.COM>
Dave Korn wrote:
On 06 September 2006 00:10, Matt Lee wrote:
I am seeing some bugs with Newlib sprintf and floating point format
specifiers. Specifically, the following bits of code work incorrectly,
Output On Xilinx PowerPC 405 platform,
+00
0000
+000
while on desktop Linux I get,
+00.0
00000
+0000
On current cygwin, I get
dk@rainbow /artimi/software> ./foo.exe
+00.0
00000
+0000
dk@rainbow /artimi/software>
The same correct results occur for x86-linux (which uses _ldtoa_r) and
mn10300-elf which uses _dtoa_r.
I should point out that if your configuration is powerpc-*spe* or
powerpc-*altivec*, then powerpc supplies its own copy of vfprintf.c
found in libc/machine/powerpc which has not been kept in lock-step with
changes in the regular version. I looked at a diff between the powerpc
version and the regular vfprintf.c and could only find one diff that
might be relevant to this situation. I have attached a patch to this
note for you to try out if your configuration is relevant (the patch is
to be applied to libc/machine/powerpc/vfprintf.c).
My only other thought is that perhaps your 1.14.0 attempt somehow got
the 1.9.0 version of the code. That is easy enough for you to verify
via debugging.
-- Jeff J.
Index: vfprintf.c
===================================================================
RCS file: /cvs/src/src/newlib/libc/machine/powerpc/vfprintf.c,v
retrieving revision 1.11
diff -u -p -r1.11 vfprintf.c
--- vfprintf.c 8 Feb 2005 01:33:16 -0000 1.11
+++ vfprintf.c 6 Sep 2006 18:00:05 -0000
@@ -875,7 +875,9 @@ reswitch: switch (ch) {
if (prec || flags & ALT)
size += prec + 1;
} else /* "0.X" */
- size = prec + 2;
+ size = (prec || flags & ALT)
+ ? prec + 2
+ : 1;
} else if (expt >= ndig) { /* fixed g fmt */
size = expt;
if (flags & ALT)