aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2015-01-07 22:12:50 +0200
committerArnold D. Robbins <arnold@skeeve.com>2015-01-07 22:12:50 +0200
commitf70399532bd105c5f42ca040846aa537a8fa27bc (patch)
treef3d38f73b87fcd8f3078d7bd6879afcff7a97e1c
parent385f22a32c3794615d713e519ae290eb09b2c4d2 (diff)
downloadegawk-f70399532bd105c5f42ca040846aa537a8fa27bc.tar.gz
egawk-f70399532bd105c5f42ca040846aa537a8fa27bc.tar.bz2
egawk-f70399532bd105c5f42ca040846aa537a8fa27bc.zip
Fix count$ in printf for dynamic width/precision.
-rw-r--r--ChangeLog2
-rw-r--r--builtin.c7
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.in9
-rw-r--r--test/Maketests5
-rw-r--r--test/printfbad4.awk5
-rw-r--r--test/printfbad4.ok2
8 files changed, 35 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 231288ab..e3a73a85 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,6 +3,8 @@
* configure.ac: Update debug flags if developing.
* awkgram.y (yylex): Regex parsing bug fix for bracket expressions.
Thanks to Mike Brennan for the report.
+ * builtin.c (format_tree): Catch non-use of count$ for dynamic
+ field width or precision.
2014-12-10 Arnold D. Robbins <arnold@skeeve.com>
diff --git a/builtin.c b/builtin.c
index 53210c4d..9b85de2b 100644
--- a/builtin.c
+++ b/builtin.c
@@ -3,7 +3,7 @@
*/
/*
- * Copyright (C) 1986, 1988, 1989, 1991-2014 the Free Software Foundation, Inc.
+ * Copyright (C) 1986, 1988, 1989, 1991-2015 the Free Software Foundation, Inc.
*
* This file is part of GAWK, the GNU implementation of the
* AWK Programming Language.
@@ -904,7 +904,10 @@ check_pos:
case '*':
if (cur == NULL)
break;
- if (! do_traditional && isdigit((unsigned char) *s1)) {
+ if (! do_traditional && used_dollar && ! isdigit((unsigned char) *s1)) {
+ fatal(_("fatal: must use `count$' on all formats or none"));
+ break; /* silence warnings */
+ } else if (! do_traditional && isdigit((unsigned char) *s1)) {
int val = 0;
for (; n0 > 0 && *s1 && isdigit((unsigned char) *s1); s1++, n0--) {
diff --git a/test/ChangeLog b/test/ChangeLog
index 95134f6b..8d6086b3 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -3,6 +3,11 @@
* Makefile.am (regexpbrack): New test.
* regexpbrack.awk, regexpbrack.in, regexpbrack.ok: New files.
+ Unrelated:
+
+ * Makefile.am (printfbad4): New test.
+ * printfbad4.awk, printfbad4.ok: New files.
+
2014-12-24 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (badbuild): New test.
diff --git a/test/Makefile.am b/test/Makefile.am
index df0da10c..12bde88d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -692,6 +692,8 @@ EXTRA_DIST = \
printfbad2.ok \
printfbad3.awk \
printfbad3.ok \
+ printfbad4.awk \
+ printfbad4.ok \
printfloat.awk \
printhuge.awk \
printhuge.ok \
@@ -1029,7 +1031,7 @@ GAWK_EXT_TESTS = \
lint lintold lintwarn \
manyfiles match1 match2 match3 mbstr1 \
nastyparm next nondec nondec2 \
- patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \
+ patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge procinfs \
profile1 profile2 profile3 profile4 profile5 profile6 profile7 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
diff --git a/test/Makefile.in b/test/Makefile.in
index 5bd39f45..55650e18 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -939,6 +939,8 @@ EXTRA_DIST = \
printfbad2.ok \
printfbad3.awk \
printfbad3.ok \
+ printfbad4.awk \
+ printfbad4.ok \
printfloat.awk \
printhuge.awk \
printhuge.ok \
@@ -1275,7 +1277,7 @@ GAWK_EXT_TESTS = \
lint lintold lintwarn \
manyfiles match1 match2 match3 mbstr1 \
nastyparm next nondec nondec2 \
- patsplit posix printfbad1 printfbad2 printfbad3 printhuge procinfs \
+ patsplit posix printfbad1 printfbad2 printfbad3 printfbad4 printhuge procinfs \
profile1 profile2 profile3 profile4 profile5 profile6 profile7 pty1 \
rebuf regnul1 regnul2 regx8bit reginttrad reint reint2 rsgetline rsglstdin rsstart1 \
rsstart2 rsstart3 rstest6 shadow sortfor sortu split_after_fpat \
@@ -3590,6 +3592,11 @@ printfbad3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printfbad4:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
procinfs:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 4104f142..5c4c40f9 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1162,6 +1162,11 @@ printfbad3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+printfbad4:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
procinfs:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/printfbad4.awk b/test/printfbad4.awk
new file mode 100644
index 00000000..dd9220ae
--- /dev/null
+++ b/test/printfbad4.awk
@@ -0,0 +1,5 @@
+BEGIN {
+ for (i = 1; i <= 10; i++) {
+ printf "%03$*d %2$d \n", 4, 5, i
+ }
+}
diff --git a/test/printfbad4.ok b/test/printfbad4.ok
new file mode 100644
index 00000000..71eed3d6
--- /dev/null
+++ b/test/printfbad4.ok
@@ -0,0 +1,2 @@
+gawk: printfbad4.awk:3: fatal: fatal: must use `count$' on all formats or none
+EXIT CODE: 2