Date: Sat, 1 Jun 2002 23:28:48 +1000 (EST) From: Bruce Evans <bde@zeta.org.au> To: Dag-Erling Smorgrav <des@ofug.org> Cc: Dima Dorfman <dima@trit.org>, <audit@FreeBSD.ORG> Subject: Re: %j for printf(9) Message-ID: <20020601232049.E2458-100000@gamplex.bde.org> In-Reply-To: <xzpptzc8dbp.fsf@flood.ping.uio.no>
next in thread | previous in thread | raw e-mail | index | archive | help
On 31 May 2002, Dag-Erling Smorgrav wrote:
> Bruce Evans <bde@zeta.org.au> writes:
> > I don't remember all the context for this. Is everything restructured so
> > that all the va_arg()'s for fetching integers are in the above patch?
>
> Yes.
>
> > If so, consider the following further restructurings:
> >
> > - merge fetch_nosign with nosign (rename it to something like
> > handle_unsigned) and use it handle all the unsigned cases that are now
> > handled by fetch_number.
> > - rename fetch_number to handle_signed and use it for only the signed cases
> > (%d and %+z).
>
> These two would actually increase code duplication.
It came out 1 line shorter with less duplication for me. Here is a patch
relative to the version in your next mail. I didn't rename fetch* to
handle*, and I may have broken something moved the initializations of
`sign' around too much. I reordered some initializations (especially for
%p) so that the order is almost (?) always (base, ..., sign, num).
%%%
--- subr_prf.c~~ Sat Jun 1 22:59:01 2002
+++ subr_prf.c Sat Jun 1 23:21:44 2002
@@ -596,7 +596,7 @@
break;
case 'd':
- sign = 1;
base = 10;
- goto fetch_number;
+ sign = 1;
+ goto fetch_sign;
case 'j':
jflag = 1;
@@ -613,8 +613,9 @@
goto fetch_nosign;
case 'p':
- num = (uintptr_t)va_arg(ap, void *);
base = 16;
sharpflag = (width == 0);
- goto nosign;
+ sign = 0;
+ num = (uintptr_t)va_arg(ap, void *);
+ goto number;
case 'q':
qflag = 1;
@@ -623,5 +624,7 @@
case 'r':
base = radix;
- goto fetch_number;
+ if (sign)
+ goto fetch_sign;
+ goto fetch_nosign;
case 's':
p = va_arg(ap, char *);
@@ -654,6 +657,8 @@
case 'z':
base = 16;
- goto fetch_number;
+ if (sign)
+ goto fetch_sign;
fetch_nosign:
+ sign = 0;
if (jflag)
num = va_arg(ap, uintmax_t);
@@ -664,20 +669,14 @@
else
num = va_arg(ap, u_int);
- goto nosign;
-fetch_number:
+ goto number;
+fetch_sign:
if (jflag)
num = va_arg(ap, intmax_t);
else if (qflag)
- num = sign ? va_arg(ap, quad_t) :
- va_arg(ap, u_quad_t);
+ num = va_arg(ap, quad_t);
else if (lflag)
- num = sign ? va_arg(ap, long) :
- va_arg(ap, u_long);
+ num = va_arg(ap, long);
else
- num = sign ? va_arg(ap, int) :
- va_arg(ap, u_int);
- goto number;
-nosign:
- sign = 0;
+ num = va_arg(ap, int);
number:
if (sign && (intmax_t)num < 0) {
%%%
To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-audit" in the body of the message
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020601232049.E2458-100000>
