This is the mail archive of the newlib@sourceware.org mailing list for the newlib project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: sprintf bugs with floating point and field specifiers?


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)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]