From 0ba01198fc96b080fc9907c1aa5b2e5f42833684 Mon Sep 17 00:00:00 2001 From: Stefan Farfeleder Date: Mon, 11 Apr 2005 10:57:54 +0000 Subject: [PATCH] Replace buggy for-loops to skip certain character with strspn(). If *fmt was '\0' (eg in the invocation 'printf %'), the for-loop would miss the terminating null character. MFC after: 1 week --- usr.bin/printf/printf.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 64206a4ee88..64aa07a0750 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -179,7 +179,7 @@ next: for (start = fmt;; ++fmt) { } /* skip to field width */ - for (; strchr(skip1, *fmt); ++fmt); + fmt += strspn(fmt, skip1); if (*fmt == '*') { if (getint(&fieldwidth)) return (1); @@ -189,7 +189,7 @@ next: for (start = fmt;; ++fmt) { havewidth = 0; /* skip to possible '.', get following precision */ - for (; strchr(skip2, *fmt); ++fmt); + fmt += strspn(fmt, skip2); } if (*fmt == '.') { /* precision present? */ @@ -203,7 +203,7 @@ next: for (start = fmt;; ++fmt) { haveprec = 0; /* skip to conversion char */ - for (; strchr(skip2, *fmt); ++fmt); + fmt += strspn(fmt, skip2); } } else haveprec = 0;