]> git.ipfire.org Git - thirdparty/open-vm-tools.git/commitdiff
lib/string: BSD printf flubbs floating point output
authorVMware, Inc <>
Tue, 26 Apr 2011 21:09:29 +0000 (14:09 -0700)
committerMarcelo Vanzin <mvanzin@vmware.com>
Tue, 26 Apr 2011 21:09:29 +0000 (14:09 -0700)
The BSD printf flubbs floating, especially when the number ends
with all zeros. The root problem is that one digit is printed
explicitly; any remaining digits need to be printed too - but
only if they aren't zero since the zero fill will take care of
them.

If there is only one digit, to print (e.g. 1.000) the calculation
handling the remaining digits comes up with -1 and, well, one gets
what they deserve.

The fix is easy - don't try to output a negative number of digits.

Signed-off-by: Marcelo Vanzin <mvanzin@vmware.com>
open-vm-tools/lib/string/bsd_vsnprintf.c

index 80140ffc1be9b78cc2398d8c1fce08b553a767bd..96455a7e74a0eaa4209e8033b372fdc0b6b46878 100644 (file)
@@ -1277,7 +1277,9 @@ bsd_vsnprintf_core(char **outbuf,
                buf[0] = *cp++;
                buf[1] = *decimal_point;
                PRINT(buf, 2);
-               PRINT(cp, ndig - 1);
+               if (ndig > 0) {
+                  PRINT(cp, ndig - 1);
+               }
                PAD(prec - ndig, zeroes);
             } else {  /* XeYYY */
                PRINT(cp, 1);