Re: %j for printf(9)

Bruce Evans <[email protected]>
Newsgroups gmane.os.freebsd.devel.audit
Message-ID <[email protected]>
On 31 May 2002, Dag-Erling Smorgrav wrote:

> Complete updated patch attached.

> Index: sys/kern/subr_prf.c
> ===================================================================
> RCS file: /home/ncvs/src/sys/kern/subr_prf.c,v
> retrieving revision 1.81
> diff -u -r1.81 subr_prf.c
> --- sys/kern/subr_prf.c	29 Apr 2002 09:15:38 -0000	1.81
> +++ sys/kern/subr_prf.c	31 May 2002 16:58:16 -0000
> ...
> @@ -491,19 +473,19 @@
>  kvprintf(char const *fmt, void (*func)(int, void*), void *arg, int radix, va_list ap)
>  {
>  #define PCHAR(c) {int cc=(c); if (func) (*func)(cc,arg); else *d++ = cc; retval++; }
> +	const char *percent;

Should be with the other char *'s.

>  	char nbuf[MAXNBUF];
>  	char *p, *q, *d;
>  	u_char *up;
>  	int ch, n;
> -	u_long ul;
> -	u_quad_t uq;
> -	int base, lflag, qflag, tmp, width, ladjust, sharpflag, neg, sign, dot;
> +	uintmax_t num;
> +	int base, lflag, jflag, qflag, tmp, width;
> +	int ladjust, sharpflag, neg, sign, dot;

When splitting this, you might consider fixing he disorder in it (but fixing
the external disorder and misarrangement of the other declarations of ints
should be in a separate patch).

> @@ -519,13 +501,15 @@
>  		padc = ' ';
>  		width = 0;
>  		while ((ch = (u_char)*fmt++) != '%') {
> -			if (ch == '\0')
> +			if (ch == '\0')

Unrelated style fix :-).

>  			PCHAR(ch);
>  		}
> -		qflag = 0; lflag = 0; ladjust = 0; sharpflag = 0; neg = 0;
> -		sign = 0; dot = 0; dwidth = 0;
> -reswitch:	switch (ch = (u_char)*fmt++) {
> +		percent = fmt - 1;
> +		qflag = jflag = lflag = ladjust = sharpflag =
> +		    neg = sign = dot = dwidth = 0;
> +reswitch:
> +		switch (ch = (u_char)*fmt++) {

Another unrelated style fix.  This one makes the patch harder to read.

> @@ -646,15 +621,8 @@
>  			goto reswitch;
>  		case 'n':
>  		case 'r':
> -			if (qflag)
> -				uq = va_arg(ap, u_quad_t);

Please remove the 'n' case, and check this a bit.  I forgot to remove it
soon after rev.1.48.

> @@ -752,10 +717,8 @@
>
>  			break;
>  		default:
> -			PCHAR('%');
> -			if (lflag)
> -				PCHAR('l');
> -			PCHAR(ch);
> +			while (percent < fmt)
> +				PCHAR(*percent++);
>  			break;
>  		}
>  	}

This seems to print all the garbage for %<garbage>.  It might be useful
to mark up the garbage.  But gcc will detect the garbage at compile time
for literal strings.

> @@ -908,7 +871,7 @@
>  }
>
>  SYSCTL_PROC(_kern, OID_AUTO, msgbuf_clear,
> -    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, &msgbuf_clear, 0,
> +    CTLTYPE_INT | CTLFLAG_RW | CTLFLAG_SECURE, &msgbuf_clear, 0,

Unrelated style fix :-).

I like the bulk of the patch.

Bruce


To Unsubscribe: send mail to [email protected]
with "unsubscribe freebsd-audit" in the body of the message
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.