summaryrefslogtreecommitdiff
path: root/usr.bin/printf/printf.c
diff options
context:
space:
mode:
authorchristos <christos@NetBSD.org>2009-10-13 19:28:31 +0000
committerchristos <christos@NetBSD.org>2009-10-13 19:28:31 +0000
commita49ff4deac0d987064fb002823220902260a1027 (patch)
treebed8515bb8cbace78df7e74f9f440ca9dcba5ef3 /usr.bin/printf/printf.c
parentf75f5aae154fcd0572e8889e4fea2a51d67bbf08 (diff)
Avoid segv on "printf '%*********s' 666", from Maksymilian Arciemowicz
Diffstat (limited to 'usr.bin/printf/printf.c')
-rw-r--r--usr.bin/printf/printf.c24
1 files changed, 17 insertions, 7 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c
index b074e4bac12..12acfe1eccc 100644
--- a/usr.bin/printf/printf.c
+++ b/usr.bin/printf/printf.c
@@ -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 @@ __COPYRIGHT("@(#) Copyright (c) 1989, 1993\
#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 @@ int main(int argc, char *argv[])
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 @@ int main(int argc, char *argv[])
/* 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);