Fix bug reported by engard.ferenc at innomed.hu whereby using the %f format
authorPaul Green <paulg@samba.org>
Wed, 9 Apr 2003 21:10:18 +0000 (21:10 +0000)
committerPaul Green <paulg@samba.org>
Wed, 9 Apr 2003 21:10:18 +0000 (21:10 +0000)
in sprintf with a value like 0.025 produced 0.250.  We were dropping the
leading zeros before the fractional digits.

lib/snprintf.c

index 0a52e17..4f3e4dc 100644 (file)
@@ -53,6 +53,9 @@
  *    got rid of fcvt code (twas buggy and made testing harder)
  *    added C99 semantics
  *
+ *  Paul Green (paulg@samba.org) April 9, 2003
+ *    fixed handling of %f when converting fractions with leading zeros.
+ *    (e.g., 0.025).
  **************************************************************/
 
 #ifndef NO_CONFIG_H /* for some tests */
@@ -725,15 +728,15 @@ static void fmtfp (char *buffer, size_t *currlen, size_t maxlen,
        if (max > 0) {
                dopr_outch (buffer, currlen, maxlen, '.');
                
+               while (zpadlen > 0) {
+                 dopr_outch (buffer, currlen, maxlen, '0');
+                 --zpadlen;
+               }
+
                while (fplace > 0) 
                        dopr_outch (buffer, currlen, maxlen, fconvert[--fplace]);
        }
        
-       while (zpadlen > 0) {
-               dopr_outch (buffer, currlen, maxlen, '0');
-               --zpadlen;
-       }
-
        while (padlen < 0) {
                dopr_outch (buffer, currlen, maxlen, ' ');
                ++padlen;