From owner-svn-src-head@FreeBSD.ORG Mon May 26 14:57:47 2014 Return-Path: Delivered-To: svn-src-head@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 B612BAE6; Mon, 26 May 2014 14:57:47 +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 A32B42B44; Mon, 26 May 2014 14:57:47 +0000 (UTC) Received: from svn.freebsd.org ([127.0.1.70]) by svn.freebsd.org (8.14.8/8.14.8) with ESMTP id s4QEvl8K071516; Mon, 26 May 2014 14:57:47 GMT (envelope-from pfg@svn.freebsd.org) Received: (from pfg@localhost) by svn.freebsd.org (8.14.8/8.14.8/Submit) id s4QEvlXE071515; Mon, 26 May 2014 14:57:47 GMT (envelope-from pfg@svn.freebsd.org) Message-Id: <201405261457.s4QEvlXE071515@svn.freebsd.org> From: "Pedro F. Giffuni" Date: Mon, 26 May 2014 14:57:47 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r266690 - 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-head@freebsd.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 26 May 2014 14:57:47 -0000 Author: pfg Date: Mon May 26 14:57:47 2014 New Revision: 266690 URL: http://svnweb.freebsd.org/changeset/base/266690 Log: printf(1): warn about incomplete uses n$ Reviewed by: jilles Obtained from: Illumos MFC after: 2 weeks Modified: head/usr.bin/printf/printf.c Modified: head/usr.bin/printf/printf.c ============================================================================== --- head/usr.bin/printf/printf.c Mon May 26 13:23:36 2014 (r266689) +++ head/usr.bin/printf/printf.c Mon May 26 14:57:47 2014 (r266690) @@ -244,11 +244,11 @@ printf_doformat(char *fmt, int *rval) /* save format argument */ fargv = gargv; } else { - fargv = NULL; + fargv = NULL; } /* skip to field width */ - while (strchr(skip1, *fmt) != NULL) { + while (*fmt && strchr(skip1, *fmt) != NULL) { *dptr++ = *fmt++; *dptr = 0; } @@ -259,12 +259,19 @@ printf_doformat(char *fmt, int *rval) l = strspn(fmt, digits); if ((l > 0) && (fmt[l] == '$')) { int idx = atoi(fmt); + if (fargv == NULL) { + warnx("incomplete use of n$"); + return (NULL); + } if (idx <= myargc) { gargv = &myargv[idx - 1]; } else { gargv = &myargv[myargc]; } fmt += l + 1; + } else if (fargv != NULL) { + warnx("incomplete use of n$"); + return (NULL); } if (getint(&fieldwidth)) @@ -296,12 +303,19 @@ printf_doformat(char *fmt, int *rval) l = strspn(fmt, digits); if ((l > 0) && (fmt[l] == '$')) { int idx = atoi(fmt); + if (fargv == NULL) { + warnx("incomplete use of n$"); + return (NULL); + } if (idx <= myargc) { gargv = &myargv[idx - 1]; } else { gargv = &myargv[myargc]; } fmt += l + 1; + } else if (fargv != NULL) { + warnx("incomplete use of n$"); + return (NULL); } if (getint(&precision))