printf family nan sign bug

classic Classic list List threaded Threaded
1 message Options
enh
Reply | Threaded
Open this post in threaded view
|

printf family nan sign bug

enh

inf is handled correctly, but nan's sign is never output. this appears to have been done deliberately, but POSIX explicitly specifies that the sign should not be lost:

A double argument representing an infinity shall be converted in one of the styles "[-]inf" or "[-]infinity"; which style is implementation-defined. Adouble argument representing a NaN shall be converted in one of the styles "[-]nan(n-char-sequence)" or "[-]nan"; which style, and the meaning of any n-char-sequence, is implementation-defined. The F conversion specifier produces "INF", "INFINITY", or "NAN" instead of "inf", "infinity", or"nan", respectively.

fix:

Index: vfprintf.c
===================================================================
RCS file: /cvs/src/lib/libc/stdio/vfprintf.c,v
retrieving revision 1.66
diff -u -r1.66 vfprintf.c
--- vfprintf.c 3 May 2014 12:36:45 -0000 1.66
+++ vfprintf.c 16 Dec 2014 20:58:04 -0000
@@ -753,10 +753,9 @@
  if (signflag)
  sign = '-';
  if (expt == INT_MAX) { /* inf or nan */
- if (*cp == 'N') {
+ if (*cp == 'N')
  cp = (ch >= 'a') ? "nan" : "NAN";
- sign = '\0';
- } else
+ else
  cp = (ch >= 'a') ? "inf" : "INF";
  size = 3;
  flags &= ~ZEROPAD;
Index: vfwprintf.c
===================================================================
RCS file: /cvs/src/lib/libc/stdio/vfwprintf.c,v
retrieving revision 1.11
diff -u -r1.11 vfwprintf.c
--- vfwprintf.c 4 Jun 2014 07:45:25 -0000 1.11
+++ vfwprintf.c 16 Dec 2014 20:58:05 -0000
@@ -731,10 +731,9 @@
  if (signflag)
  sign = '-';
  if (expt == INT_MAX) { /* inf or nan */
- if (*cp == 'N') {
+ if (*cp == 'N')
  cp = (ch >= 'a') ? L"nan" : L"NAN";
- sign = '\0';
- } else
+ else
  cp = (ch >= 'a') ? L"inf" : L"INF";
  size = 3;
  flags &= ~ZEROPAD;


  --elliott