From owner-svn-src-all@FreeBSD.ORG Thu May 8 20:21:00 2014 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [8.8.178.115]) (using TLSv1 with cipher ADH-AES256-SHA (256/256 bits)) (No client certificate requested) by hub.freebsd.org (Postfix) with ESMTPS id 58C60F17; Thu, 8 May 2014 20:21:00 +0000 (UTC) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:1900:2254:2068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mx1.freebsd.org (Postfix) with ESMTPS id 2C1C0F28; Thu, 8 May 2014 20:21:00 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s48KKxko056006; Thu, 8 May 2014 20:20:59 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s48KKxP2056005; Thu, 8 May 2014 20:20:59 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201405082020.s48KKxP2056005@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Thu, 8 May 2014 20:20:59 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r265706 - head/usr.bin/printf X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 08 May 2014 20:21:00 -0000 Author: pfg Date: Thu May 8 20:20:59 2014 New Revision: 265706 URL: http://svnweb.freebsd.org/changeset/base/265706 Log: Fix the incorrect handling of %b and \c in printf(1) This is required for POSIX compliance. Obtained from: Garrett D'Amore (Illumos) MFC after: 4 days Modified: head/usr.bin/printf/printf.c Modified: head/usr.bin/printf/printf.c ============================================================================== --- head/usr.bin/printf/printf.c Thu May 8 20:02:38 2014 (r265705) +++ head/usr.bin/printf/printf.c Thu May 8 20:20:59 2014 (r265706) @@ -110,7 +110,7 @@ int main(int argc, char *argv[]) { size_t len; - int chopped, end, rval; + int end, rval; char *format, *fmt, *start; #ifndef SHELL int ch; @@ -151,7 +151,7 @@ main(int argc, char *argv[]) * up the format string. */ fmt = format = *argv; - chopped = escape(fmt, 1, &len); /* backslash interpretation */ + escape(fmt, 1, &len); /* backslash interpretation */ rval = end = 0; gargv = ++argv; @@ -195,7 +195,7 @@ main(int argc, char *argv[]) return (1); } fwrite(start, 1, fmt - start, stdout); - if (chopped || !*gargv) { + if (!*gargv) { #ifdef SHELL INTON; #endif @@ -241,8 +241,8 @@ printf_doformat(char *fmt, int *rval) maxargv = gargv; fmt += l + 1; - /* save format argument */ - fargv = gargv; + /* save format argument */ + fargv = gargv; } else { fargv = NULL; } @@ -352,7 +352,7 @@ printf_doformat(char *fmt, int *rval) /* save the current arg offset, and set to the format arg */ if (fargv != NULL) { - gargv = fargv; + gargv = fargv; } convch = *fmt; @@ -371,12 +371,10 @@ printf_doformat(char *fmt, int *rval) return (NULL); } getout = escape(p, 0, &len); - *(fmt - 1) = 's'; - PF(start, p); - *(fmt - 1) = 'b'; + fputs(p, stdout); free(p); if (getout) - return (fmt); + exit(*rval); break; } case 'c': { @@ -488,9 +486,13 @@ escape(char *fmt, int percent, size_t *l *store = '\b'; break; case 'c': - *store = '\0'; - *len = store - save; - return (1); + if (!percent) { + *store = '\0'; + *len = store - save; + return (1); + } + *store = 'c'; + break; case 'f': /* form-feed */ *store = '\f'; break;