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:

> Bruce Evans <[email protected]> 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 [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.