diff options
author | fenner <fenner@FreeBSD.org> | 1996-03-20 18:28:48 +0000 |
---|---|---|
committer | fenner <fenner@FreeBSD.org> | 1996-03-20 18:28:48 +0000 |
commit | 78136570e7e473b76eb91767a92783e8c9f27fa5 (patch) | |
tree | 5441fcc318b1b89d2618505a60e086c3ed4a0731 /lib | |
parent | 4abce83b7ae671f0d5bd81cb352c79f5083309af (diff) | |
download | FreeBSD-src-78136570e7e473b76eb91767a92783e8c9f27fa5.zip FreeBSD-src-78136570e7e473b76eb91767a92783e8c9f27fa5.tar.gz |
The 4.4-lite vfprintf counted the %# hex prefix and the sign in
the precision; ANSI X3J11 is not crystal clear but certainly says
that the precision specifies the number of /digits/, and signs
and "0x" aren't really digits.
NetBSD already has a similar patch.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdio/vfprintf.c | 14 |
1 files changed, 6 insertions, 8 deletions
diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index 3c3d4d3..0f241de 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -306,8 +306,7 @@ vfprintf(fp, fmt0, ap) u_quad_t uqval; /* %q integers */ int base; /* base for [diouxX] conversion */ int dprec; /* a copy of prec if [diouxX], 0 otherwise */ - int fieldsz; /* field size expanded by sign, etc */ - int realsz; /* field size expanded by dprec */ + int realsz; /* field size expanded by dprec, sign, etc */ int size; /* size of converted field or string */ char *xdigs; /* digits for [xX] conversion */ #define NIOV 8 @@ -708,14 +707,13 @@ number: if ((dprec = prec) >= 0) * floating precision; finally, if LADJUST, pad with blanks. * * Compute actual size, so we know how much to pad. - * fieldsz excludes decimal prec; realsz includes it. + * size excludes decimal prec; realsz includes it. */ - fieldsz = size; + realsz = dprec > size ? dprec : size; if (sign) - fieldsz++; + realsz++; else if (flags & HEXPREFIX) - fieldsz += 2; - realsz = dprec > fieldsz ? dprec : fieldsz; + realsz += 2; /* right-adjusting blank padding */ if ((flags & (LADJUST|ZEROPAD)) == 0) @@ -735,7 +733,7 @@ number: if ((dprec = prec) >= 0) PAD(width - realsz, zeroes); /* leading zeroes from decimal precision */ - PAD(dprec - fieldsz, zeroes); + PAD(dprec - size, zeroes); /* the string or number proper */ #ifdef FLOATING_POINT |