Module Name: src Committed By: sborrill Date: Wed Oct 14 18:37:30 UTC 2009
Modified Files: src/usr.bin/printf [netbsd-5-0]: printf.c Log Message: Pull up the following revisions(s) (requested by christos in ticket #1091): usr.bin/printf/printf.c: revision 1.34 Avoid segv on "printf '%*********s' 666". To generate a diff of this commit: cvs rdiff -u -r1.33 -r1.33.8.1 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.33.8.1 --- src/usr.bin/printf/printf.c:1.33 Mon Jul 21 14:19:24 2008 +++ src/usr.bin/printf/printf.c Wed Oct 14 18:37:30 2009 @@ -1,4 +1,4 @@ -/* $NetBSD: printf.c,v 1.33 2008/07/21 14:19:24 lukem Exp $ */ +/* $NetBSD: printf.c,v 1.33.8.1 2009/10/14 18:37:30 sborrill 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.33.8.1 2009/10/14 18:37:30 sborrill 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);