Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 26 May 2014 14:57:47 +0000 (UTC)
From:      "Pedro F. Giffuni" <pfg@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r266690 - head/usr.bin/printf
Message-ID:  <201405261457.s4QEvlXE071515@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
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))



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201405261457.s4QEvlXE071515>