Module Name:    src
Committed By:   christos
Date:           Tue Oct 13 19:28:31 UTC 2009

Modified Files:
        src/usr.bin/printf: printf.c

Log Message:
Avoid segv on "printf '%*********s' 666", from Maksymilian Arciemowicz


To generate a diff of this commit:
cvs rdiff -u -r1.33 -r1.34 src/usr.bin/printf/printf.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/printf/printf.c
diff -u src/usr.bin/printf/printf.c:1.33 src/usr.bin/printf/printf.c:1.34
--- src/usr.bin/printf/printf.c:1.33	Mon Jul 21 10:19:24 2008
+++ src/usr.bin/printf/printf.c	Tue Oct 13 15:28:31 2009
@@ -1,4 +1,4 @@
-/*	$NetBSD: printf.c,v 1.33 2008/07/21 14:19:24 lukem Exp $	*/
+/*	$NetBSD: printf.c,v 1.34 2009/10/13 19:28:31 christos Exp $	*/
 
 /*
  * Copyright (c) 1989, 1993
@@ -41,7 +41,7 @@
 #if 0
 static char sccsid[] = "@(#)printf.c	8.2 (Berkeley) 3/22/95";
 #else
-__RCSID("$NetBSD: printf.c,v 1.33 2008/07/21 14:19:24 lukem Exp $");
+__RCSID("$NetBSD: printf.c,v 1.34 2009/10/13 19:28:31 christos Exp $");
 #endif
 #endif /* not lint */
 
@@ -155,7 +155,7 @@
 	gargv = ++argv;
 
 #define SKIP1	"#-+ 0"
-#define SKIP2	"*0123456789"
+#define SKIP2	"0123456789"
 	do {
 		/*
 		 * Basic algorithm is to scan the format string for conversion
@@ -185,13 +185,23 @@
 
 			/* skip to field width */
 			fmt += strspn(fmt, SKIP1);
-			fieldwidth = *fmt == '*' ? getwidth() : -1;
+			if (*fmt == '*') {
+				fmt++;
+				fieldwidth = getwidth();
+			} else
+				fieldwidth = -1;
 
 			/* skip to possible '.', get following precision */
 			fmt += strspn(fmt, SKIP2);
-			if (*fmt == '.')
-				++fmt;
-			precision = *fmt == '*' ? getwidth() : -1;
+			if (*fmt == '.') {
+				fmt++;
+				if (*fmt == '*') {
+					fmt++;
+					precision = getwidth();
+				} else
+					precision = -1;
+			} else
+				precision = -1;
 
 			fmt += strspn(fmt, SKIP2);
 

Reply via email to