Check for format character precision argument before using it

This commit is contained in:
Cody Peter Mello 2018-09-14 17:29:06 -07:00
parent 2dc7e5ff1a
commit 6cf37e9d15
4 changed files with 9 additions and 0 deletions

View File

@ -23,3 +23,6 @@ and also if CONVFMT changed.
7. unary-plus: Unary plus on a string constant returned the string.
Instead, it should convert the value to numeric and give that value.
8. missing-precision: When using the format string "%*s", the precision
argument was used without checking if it was present first.

View File

@ -0,0 +1 @@
BEGIN { printf("%*s"); }

View File

@ -0,0 +1,2 @@
./a.out: not enough args in printf(%*s)
source line number 1

3
run.c
View File

@ -863,6 +863,9 @@ int format(char **pbuf, int *pbufsize, const char *s, Node *a) /* printf-like co
FATAL("'$' not permitted in awk formats");
}
if (*s == '*') {
if (a == NULL) {
FATAL("not enough args in printf(%s)", os);
}
x = execute(a);
a = a->nnext;
sprintf(t-1, "%d", fmtwd=(int) getfval(x));