From 82941964305894b84da3b17411dc3f12146b618a Mon Sep 17 00:00:00 2001 From: Peter Wemm Date: Sat, 10 Jul 1999 15:27:05 +0000 Subject: Fixes for a couple of problems in last commit: 1. Printing large quads in small bases overflowed the buffer if sizeof(u_quad_t) > sizeof(u_long). 2. The sharpflag checks had operator precedence bugs due to excessive parentheses in all the wrong places. 3. The explicit 0L was bogus in the quad_t comparison and useless in the long comparision. 4. There was some more bitrot in the comment about ksprintn(). Our ksprintn() handles bases up to 36 as well as down to 2. Bruce has other complaints about using %q in kernel and would rather we went towards using the C9X style %ll and/or %j. (I agree for that matter, as long as gcc/egcs know how to deal with that.) Submitted by: bde --- sys/kern/subr_prf.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/kern/subr_prf.c b/sys/kern/subr_prf.c index 299de193f6e5..40c2365455d4 100644 --- a/sys/kern/subr_prf.c +++ b/sys/kern/subr_prf.c @@ -36,7 +36,7 @@ * SUCH DAMAGE. * * @(#)subr_prf.c 8.3 (Berkeley) 1/21/94 - * $Id: subr_prf.c,v 1.54 1999/06/07 18:26:26 archie Exp $ + * $Id: subr_prf.c,v 1.55 1999/07/09 17:54:39 peter Exp $ */ #include @@ -60,8 +60,8 @@ #define TOTTY 0x02 #define TOLOG 0x04 -/* Max number conversion buffer length: a long in base 2, plus NUL byte. */ -#define MAXNBUF (sizeof(long) * NBBY + 1) +/* Max number conversion buffer length: a u_quad_t in base 2, plus NUL byte. */ +#define MAXNBUF (sizeof(quad_t) * NBBY + 1) struct putchar_arg { int flags; @@ -387,7 +387,7 @@ snprintf_func(int ch, void *arg) } /* - * Put a NUL-terminated ASCII number (base <= 16) in a buffer in reverse + * Put a NUL-terminated ASCII number (base <= 36) in a buffer in reverse * order; return an optional length and a pointer to the last character * written in the buffer (i.e., the first character of the string). * The buffer pointed to by `nbuf' must have length >= MAXNBUF. @@ -409,7 +409,7 @@ ksprintn(nbuf, ul, base, lenp) *lenp = p - nbuf; return (p); } -/* ksprintn, but for a quad_t */ +/* ksprintn, but for a quad_t. */ static char * ksprintqn(nbuf, uq, base, lenp) char *nbuf; @@ -670,19 +670,19 @@ reswitch: switch (ch = (u_char)*fmt++) { nosign: sign = 0; number: if (qflag) { - if (sign && (quad_t)uq < 0L) { + if (sign && (quad_t)uq < 0) { neg = 1; uq = -(quad_t)uq; } p = ksprintqn(nbuf, uq, base, &tmp); } else { - if (sign && (long)ul < 0L) { + if (sign && (long)ul < 0) { neg = 1; ul = -(long)ul; } p = ksprintn(nbuf, ul, base, &tmp); } - if (sharpflag && qflag ? (uq != 0) : (ul != 0)) { + if (sharpflag && (qflag ? uq != 0 : ul != 0)) { if (base == 8) tmp++; else if (base == 16) -- cgit v1.2.3