diff options
author | das <das@FreeBSD.org> | 2003-04-14 11:24:53 +0000 |
---|---|---|
committer | das <das@FreeBSD.org> | 2003-04-14 11:24:53 +0000 |
commit | c01851b648b124bfc6d97b44841f0f513d2352be (patch) | |
tree | c9518de5ec2d21864a9bd486a2b7d30ccda5ef22 /lib/libc | |
parent | 6efce81948c67ccea6ca2bb90a447bb8da444c8b (diff) | |
download | FreeBSD-src-c01851b648b124bfc6d97b44841f0f513d2352be.zip FreeBSD-src-c01851b648b124bfc6d97b44841f0f513d2352be.tar.gz |
Fix a bug where printf was erroneously printing a decimal point for
%f and sufficiently short %g specifiers where the precision was
explicitly zero, no '#' flag was specified, and the floating point
argument was > 0 and <= 0.5. While at it, add some comments to better
explain the relevant bits of code.
Noticed by: Christoph Kukulies <kuku@physik.rwth-aachen.de>
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/vfprintf.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 8ca5ac4..0f0cf52 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -928,12 +928,14 @@ fp_begin: if (prec > 1 || flags & ALT) ++size; } else { - if (expt > 0) { + /* space for digits before decimal point */ + if (expt > 0) size = expt; - if (prec || flags & ALT) - size += prec + 1; - } else /* "0.X" */ - size = prec + 2; + else /* "0" */ + size = 1; + /* space for decimal pt and following digits */ + if (prec || flags & ALT) + size += prec + 1; if (grouping && expt > 0) { /* space for thousands' grouping */ nseps = nrepeats = 0; @@ -1163,9 +1165,9 @@ number: if ((dprec = prec) >= 0) } else { /* glue together f_p fragments */ if (!expchar) { /* %[fF] or sufficiently short %[gG] */ if (expt <= 0) { - buf[0] = '0'; - buf[1] = *decimal_point; - PRINT(buf, 2); + PRINT(zeroes, 1); + if (prec || flags & ALT) + PRINT(decimal_point, 1); PAD(-expt, zeroes); /* already handled initial 0's */ prec += expt; |