From owner-svn-src-all@freebsd.org Sat Apr 29 21:48:13 2017 Return-Path: Delivered-To: svn-src-all@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 5F37DD568B4; Sat, 29 Apr 2017 21:48:13 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::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 15BB67C3; Sat, 29 Apr 2017 21:48:13 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id v3TLmCQt070708; Sat, 29 Apr 2017 21:48:12 GMT (envelope-from jilles@FreeBSD.org) Received: (from jilles@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id v3TLmCmm070707; Sat, 29 Apr 2017 21:48:12 GMT (envelope-from jilles@FreeBSD.org) Message-Id: <201704292148.v3TLmCmm070707@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: jilles set sender to jilles@FreeBSD.org using -f From: Jilles Tjoelker Date: Sat, 29 Apr 2017 21:48:12 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r317598 - 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.23 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: Sat, 29 Apr 2017 21:48:13 -0000 Author: jilles Date: Sat Apr 29 21:48:11 2017 New Revision: 317598 URL: https://svnweb.freebsd.org/changeset/base/317598 Log: printf: Output formatted data directly, instead of via asprintf. Long ago, sh used to have its own optimized and restricted string formatting implementation, which the printf builtin had to bypass via asprintf() to a temporary buffer. Since sh has used libc's string formatting implementation for a long time, remove the workaround. Add a check to keep printf %c '' working the same way (output nothing); POSIX allows both outputting nothing and outputting a NUL byte. Also, this change avoids silently discarding format directives for whose output asprintf() cannot allocate memory. Modified: head/usr.bin/printf/printf.c Modified: head/usr.bin/printf/printf.c ============================================================================== --- head/usr.bin/printf/printf.c Sat Apr 29 19:20:50 2017 (r317597) +++ head/usr.bin/printf/printf.c Sat Apr 29 21:48:11 2017 (r317598) @@ -70,20 +70,15 @@ static const char rcsid[] = #endif #define PF(f, func) do { \ - char *b = NULL; \ if (havewidth) \ if (haveprec) \ - (void)asprintf(&b, f, fieldwidth, precision, func); \ + (void)printf(f, fieldwidth, precision, func); \ else \ - (void)asprintf(&b, f, fieldwidth, func); \ + (void)printf(f, fieldwidth, func); \ else if (haveprec) \ - (void)asprintf(&b, f, precision, func); \ + (void)printf(f, precision, func); \ else \ - (void)asprintf(&b, f, func); \ - if (b) { \ - (void)fputs(b, stdout); \ - free(b); \ - } \ + (void)printf(f, func); \ } while (0) static int asciicode(void); @@ -394,7 +389,8 @@ printf_doformat(char *fmt, int *rval) char p; p = getchr(); - PF(start, p); + if (p != '\0') + PF(start, p); break; } case 's': {