Merge pull request #14 from melloc/missing-precision

Check for format character precision argument before using it
This commit is contained in:
onetrueawk 2019-01-21 13:46:44 -05:00 committed by GitHub
commit 40b9214d2a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
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));