NetBSD-Bugs archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

lib/44113: printf(3) should ignore zero padding for nan/inf



>Number:         44113
>Category:       lib
>Synopsis:       printf(3) should ignore zero padding for nan/inf
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    lib-bug-people
>State:          open
>Class:          sw-bug
>Submitter-Id:   net
>Arrival-Date:   Thu Nov 18 15:00:01 +0000 2010
>Originator:     Nicolas Joly
>Release:        NetBSD 5.99.39
>Organization:
Institut Pasteur
>Environment:
System: NetBSD lanfeust.sis.pasteur.fr 5.99.39 NetBSD 5.99.39 (LANFEUST) #14: 
Thu Nov 18 13:06:13 CET 2010 
njoly%lanfeust.sis.pasteur.fr@localhost:/local/src/NetBSD/obj.amd64/sys/arch/amd64/compile/LANFEUST
 amd64
Architecture: x86_64
Machine: amd64
>Description:
printf(3) family of functions do obey zero padding flag when printing
nan/inf values, but should better not.

A call such as `printf("%010f", NAN)' will generate the following `0000000nan'
string, which can give unexpected results and prevents further parsing; calls
such as strtod(3) will fails ... Generating a space padded string `       nan'
seems much better in that case.
>How-To-Repeat:
>Fix:
The following patch do seems to do the trick.

Index: lib/libc/stdio/vfwprintf.c
===================================================================
RCS file: /cvsroot/src/lib/libc/stdio/vfwprintf.c,v
retrieving revision 1.21
diff -u -p -r1.21 vfwprintf.c
--- lib/libc/stdio/vfwprintf.c  31 Jul 2010 08:47:34 -0000      1.21
+++ lib/libc/stdio/vfwprintf.c  18 Nov 2010 14:36:07 -0000
@@ -1131,6 +1131,7 @@ fp_common:
                                        result = (ch >= 'a') ? STRCONST("inf") :
                                            STRCONST("INF");
                                size = 3;
+                               flags &= ~ZEROPAD;
                                break;
                        }
 #else
@@ -1161,6 +1162,7 @@ fp_common:
                                else
                                        result = STRCONST("inf");
                                size = 3;
+                               flags &= ~ZEROPAD;
                                break;
                        }
                        if (isnan(_double)) {
@@ -1169,6 +1171,7 @@ fp_common:
                                else
                                        result = STRCONST("nan");
                                size = 3;
+                               flags &= ~ZEROPAD;
                                break;
                        }
 



Home | Main Index | Thread Index | Old Index