From owner-freebsd-bugs@FreeBSD.ORG Tue Jul 19 16:58:55 2005 Return-Path: X-Original-To: freebsd-bugs@FreeBSD.org Delivered-To: freebsd-bugs@FreeBSD.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 72DA216A41F for ; Tue, 19 Jul 2005 16:58:55 +0000 (GMT) (envelope-from hiroo@oikumene.gcd.org) Received: from smtp2.inetd.co.jp (smtp2.inetd.co.jp [211.13.220.139]) by mx1.FreeBSD.org (Postfix) with ESMTP id E4EBE43D45 for ; Tue, 19 Jul 2005 16:58:54 +0000 (GMT) (envelope-from hiroo@oikumene.gcd.org) Received: from chrysanthe.oikumene.gcd.org (206.162.192.61.tokyo.global.alpha-net.ne.jp [61.192.162.206]) by smtp2.inetd.co.jp (Postfix) with ESMTP id DFE03C4F4E for ; Wed, 20 Jul 2005 01:58:52 +0900 (JST) Received: from jezebel.oikumene.gcd.org (jezebel.oikumene.gcd.org [192.168.0.20]) (authenticated bits=0) by chrysanthe.oikumene.gcd.org (8.13.3/8.13.3) with ESMTP id j6JE79Xq001154 for ; Tue, 19 Jul 2005 23:07:09 +0900 (JST) (envelope-from hiroo@oikumene.gcd.org) Date: Tue, 19 Jul 2005 23:07:08 +0900 Message-ID: <86y8823n5f.wl%hiroo@oikumene.gcd.org> From: Hiroo Ono To: freebsd-bugs@FreeBSD.org In-Reply-To: <200507180356.j6I3uoY5036156@freefall.freebsd.org> References: <200507180356.j6I3uoY5036156@freefall.freebsd.org> User-Agent: Wanderlust/2.14.0 (Africa) SEMI/1.14.6 (Maruoka) FLIM/1.14.7 (=?ISO-8859-4?Q?Sanj=F2?=) APEL/10.6 Emacs/21.3 (i386--freebsd) MULE/5.0 (SAKAKI) MIME-Version: 1.0 (generated by SEMI 1.14.6 - "Maruoka") Content-Type: text/plain; charset=US-ASCII Cc: Subject: Re: bin/39116: /usr/bin/printf X-BeenThere: freebsd-bugs@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Bug reports List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Tue, 19 Jul 2005 16:58:55 -0000 The fix for this PR is done in HEAD src/usr.bin/printf/printf.c rev.1.22 to 1.25 I made a MFC patch for this, and tested on RELENG_4, FreeBSD 4.11-STABLE #26: Sat Jul 2 02:02:27 JST 2005. Tested with the three cases in this PR. The results are same as on FreeBSD 5.4R-p4. chrysanthe% ./printf '\45\n' % chrysanthe% ./printf '%%%s\n' a b c %a %b %c chrysanthe% ./printf '%*i\n' 0 Would somebody commit it to RELENG_4 and close this PR? PR: 39116 Submitted by: Egil Brendsdal 1.25 Fix duplicate % in %b format introduced in rev 1.22. 1.24 Let printf(1) tell the difference between zero width/precision and unspecified width/precision. 1.23 Allow format strings containing "%%" to be reused. 1.22 Allow `%' to be written out with an octal escape (\45 or \045). ---------- --- printf.c.orig 2005-07-19 12:58:43.513437500 +0900 +++ printf.c 2005-07-19 11:04:20.013437500 +0900 @@ -73,12 +73,12 @@ #define PF(f, func) do { \ char *b = NULL; \ - if (fieldwidth) \ - if (precision) \ + if (havewidth) \ + if (haveprec) \ (void)asprintf(&b, f, fieldwidth, precision, func); \ else \ (void)asprintf(&b, f, fieldwidth, func); \ - else if (precision) \ + else if (haveprec) \ (void)asprintf(&b, f, precision, func); \ else \ (void)asprintf(&b, f, func); \ @@ -89,7 +89,7 @@ } while (0) static int asciicode(void); -static int escape(char *); +static int escape(char *, int); static int getchr(void); static int getdouble(double *); static int getint(int *); @@ -111,7 +111,7 @@ char *argv[]; { static const char *skip1, *skip2; - int ch, chopped, end, fieldwidth, precision, rval; + int ch, chopped, end, fieldwidth, haveprec, havewidth, precision, rval; char convch, nextch, *format, *fmt, *start; #ifndef BUILTIN @@ -143,7 +143,7 @@ skip1 = "#-+ 0"; skip2 = "0123456789"; - chopped = escape(fmt = format = *argv); /* backslash interpretation */ + chopped = escape(fmt = format = *argv, 1);/* backslash interpretation */ rval = 0; gargv = ++argv; for (;;) { @@ -173,8 +173,8 @@ if (*fmt == '%') { if (*++fmt != '%') break; - *fmt++ = '\0'; - (void)printf("%s", start); + (void)printf("%.*s", (int)(fmt - start), start); + fmt++; goto next; } } @@ -184,9 +184,10 @@ if (*fmt == '*') { if (getint(&fieldwidth)) return (1); + havewidth = 1; ++fmt; } else { - fieldwidth = 0; + havewidth = 0; /* skip to possible '.', get following precision */ for (; strchr(skip2, *fmt); ++fmt); @@ -197,15 +198,16 @@ if (*fmt == '*') { if (getint(&precision)) return (1); + haveprec = 1; ++fmt; } else { - precision = 0; + haveprec = 0; /* skip to conversion char */ for (; strchr(skip2, *fmt); ++fmt); } } else - precision = 0; + haveprec = 0; if (!*fmt) { warnx1("missing format character", NULL, NULL); return (1); @@ -228,7 +230,7 @@ warnx2("%s", strerror(ENOMEM), NULL); return (1); } - getout = escape(p); + getout = escape(p, 0); *(fmt - 1) = 's'; PF(start, p); *(fmt - 1) = 'b'; @@ -323,8 +325,9 @@ } static int -escape(fmt) +escape(fmt, percent) register char *fmt; + int percent; { register char *store; register int value, c; @@ -376,7 +379,11 @@ value += *fmt - '0'; } --fmt; - *store = value; + if (percent && value == '%') { + *store++ = '%'; + *store = '%'; + } else + *store = value; break; default: *store = *fmt; ----------