From: VMware, Inc <> Date: Tue, 26 Apr 2011 21:09:29 +0000 (-0700) Subject: lib/string: BSD printf flubbs floating point output X-Git-Tag: 2011.04.25-402641~30 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=94cf9dfe92e121f5b3a56f36abf156f6a44be7dc;p=thirdparty%2Fopen-vm-tools.git lib/string: BSD printf flubbs floating point output 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 --- diff --git a/open-vm-tools/lib/string/bsd_vsnprintf.c b/open-vm-tools/lib/string/bsd_vsnprintf.c index 80140ffc1..96455a7e7 100644 --- a/open-vm-tools/lib/string/bsd_vsnprintf.c +++ b/open-vm-tools/lib/string/bsd_vsnprintf.c @@ -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);