diff options
author | joerg <joerg@FreeBSD.org> | 1995-05-07 07:00:18 +0000 |
---|---|---|
committer | joerg <joerg@FreeBSD.org> | 1995-05-07 07:00:18 +0000 |
commit | 99ee13afa542c786c0a13c179397bda6ad0b989b (patch) | |
tree | 11454b982f22fe5b348c15f858154abc5cb4587f | |
parent | bf30e374f0e9ee0cf74eeec29e283bf75cc1a38b (diff) | |
download | FreeBSD-src-99ee13afa542c786c0a13c179397bda6ad0b989b.zip FreeBSD-src-99ee13afa542c786c0a13c179397bda6ad0b989b.tar.gz |
Make the syntax checks for the format string more strict. The string
"%8*s" is no longer considered to be a valid format description.
This closes PR bin/386.
-rw-r--r-- | usr.bin/printf/printf.c | 31 |
1 files changed, 19 insertions, 12 deletions
diff --git a/usr.bin/printf/printf.c b/usr.bin/printf/printf.c index 69f0c8e..3136703 100644 --- a/usr.bin/printf/printf.c +++ b/usr.bin/printf/printf.c @@ -132,7 +132,7 @@ main(argc, argv) * up the format string. */ skip1 = "#-+ 0"; - skip2 = "*0123456789"; + skip2 = "0123456789"; escape(fmt = format = *argv); /* backslash interpretation */ gargv = ++argv; @@ -170,21 +170,28 @@ next: for (start = fmt;; ++fmt) { if (*fmt == '*') { if (getint(&fieldwidth)) return (1); - } else + ++fmt; + } else { fieldwidth = 0; - /* skip to possible '.', get following precision */ - for (; strchr(skip2, *fmt); ++fmt); - if (*fmt == '.') + /* skip to possible '.', get following precision */ + for (; strchr(skip2, *fmt); ++fmt); + } + if (*fmt == '.') { + /* precision present? */ ++fmt; - if (*fmt == '*') { - if (getint(&precision)) - return (1); + if (*fmt == '*') { + if (getint(&precision)) + return (1); + ++fmt; + } else { + precision = 0; + + /* skip to conversion char */ + for (; strchr(skip2, *fmt); ++fmt); + } } else precision = 0; - - /* skip to conversion char */ - for (; strchr(skip2, *fmt); ++fmt); if (!*fmt) { warnx("missing format character", NULL, NULL); return (1); @@ -227,7 +234,7 @@ next: for (start = fmt;; ++fmt) { break; } default: - warnx("illegal format character", NULL, NULL); + warnx("illegal format character %c", convch, NULL); return (1); } *fmt = nextch; |