aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--interpret.h24
-rw-r--r--pc/Makefile.tst11
-rw-r--r--test/ChangeLog7
-rw-r--r--test/Makefile.am7
-rw-r--r--test/Makefile.in14
-rw-r--r--test/Maketests7
-rw-r--r--test/functab6.awk1
-rw-r--r--test/functab6.ok2
-rw-r--r--test/symtab10.in4
-rw-r--r--test/symtab10.ok11
11 files changed, 64 insertions, 30 deletions
diff --git a/ChangeLog b/ChangeLog
index 09512cf7..e8f993eb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2021-09-10 Arnold D. Robbins <arnold@skeeve.com>
+
+ * interpret.h: For Op_subscript, don't allow references into
+ FUNCTAB and SYMTAB to create new elements. Thanks to
+ Jason C. Kwan <jasonckwan@yahoo.com> for the bug report.
+
2021-09-09 Arnold D. Robbins <arnold@skeeve.com>
Move to Autoconf 2.71 (finally!)
diff --git a/interpret.h b/interpret.h
index 2ed4f01a..4495d8cc 100644
--- a/interpret.h
+++ b/interpret.h
@@ -67,6 +67,7 @@ r_interpret(INSTRUCTION *code)
Regexp *rp;
NODE *set_array = NULL; /* array with a post-assignment routine */
NODE *set_idx = NULL; /* the index of the array element */
+ bool subscript_in_array;
/* array subscript */
@@ -265,14 +266,27 @@ uninitialized_scalar:
t2 = mk_sub(pc->sub_count);
t1 = POP_ARRAY(false);
- if (do_lint && in_array(t1, t2) == NULL) {
+ subscript_in_array = (in_array(t1, t2) != NULL);
+
+ if (! subscript_in_array) {
t2 = force_string(t2);
- lintwarn(_("reference to uninitialized element `%s[\"%.*s\"]'"),
- array_vname(t1), (int) t2->stlen, t2->stptr);
- if (t2->stlen == 0)
- lintwarn(_("subscript of array `%s' is null string"), array_vname(t1));
+
+ if (t1 == func_table) {
+ fatal(_("reference to uninitialized element `%s[\"%.*s\"] is not allowed'"),
+ "FUNCTAB", (int) t2->stlen, t2->stptr);
+ } else if (t1 == symbol_table) {
+ fatal(_("reference to uninitialized element `%s[\"%.*s\"] is not allowed'"),
+ "SYMTAB", (int) t2->stlen, t2->stptr);
+ } else if (do_lint) {
+ lintwarn(_("reference to uninitialized element `%s[\"%.*s\"]'"),
+ array_vname(t1), (int) t2->stlen, t2->stptr);
+ if (t2->stlen == 0)
+ lintwarn(_("subscript of array `%s' is null string"), array_vname(t1));
+ }
}
+ // continue the regular processing
+
/* for FUNCTAB, get the name as the element value */
if (t1 == func_table) {
static bool warned = false;
diff --git a/pc/Makefile.tst b/pc/Makefile.tst
index a11dc1b7..04dbbd44 100644
--- a/pc/Makefile.tst
+++ b/pc/Makefile.tst
@@ -198,7 +198,7 @@ GAWK_EXT_TESTS = \
devfd devfd1 devfd2 dfacheck1 dumpvars \
errno exit fieldwdth forcenum \
fpat1 fpat2 fpat3 fpat4 fpat5 fpat6 fpat7 fpat8 fpat9 fpatnull \
- fsfwfs funlen functab1 functab2 functab3 \
+ fsfwfs funlen functab1 functab2 functab3 functab6 \
fwtest fwtest2 fwtest3 fwtest4 fwtest5 fwtest6 fwtest7 fwtest8 \
genpot gensub gensub2 gensub3 getlndir gnuops2 gnuops3 gnureops gsubind \
icasefs icasers id igncdym igncfs ignrcas2 ignrcas4 ignrcase incdupe \
@@ -251,7 +251,7 @@ SHLIB_TESTS = \
# List of the tests which should be run with --debug option:
-NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3 symtab10
+NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3
# List of the tests which should be run with --lint option:
NEED_LINT = \
@@ -2760,6 +2760,11 @@ functab3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+functab6:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
fwtest:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@@ -3322,7 +3327,7 @@ symtab7:
symtab10:
@echo $@
- @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
symtab11:
diff --git a/test/ChangeLog b/test/ChangeLog
index 007d182b..f25469c1 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -1,3 +1,10 @@
+2021-09-10 Arnold D. Robbins <arnold@skeeve.com>
+
+ * Makefile.am (EXTRA_DIST): functab6, new test.
+ * functab6.awk, functab6.ok: New files.
+ * symtab10.ok: Modified after code change.
+ * symtab10.in: Removed.
+
2021-09-06 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am (EXTRA_DIST): typeof6, new test.
diff --git a/test/Makefile.am b/test/Makefile.am
index bd800fff..3663ac28 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -420,6 +420,8 @@ EXTRA_DIST = \
functab4.ok \
functab5.awk \
functab5.ok \
+ functab6.awk \
+ functab6.ok \
funlen.awk \
funlen.in \
funlen.ok \
@@ -1280,7 +1282,6 @@ EXTRA_DIST = \
symtab9.awk \
symtab9.ok \
symtab10.awk \
- symtab10.in \
symtab10.ok \
symtab11.awk \
symtab11.ok \
@@ -1445,7 +1446,7 @@ GAWK_EXT_TESTS = \
devfd devfd1 devfd2 dfacheck1 dumpvars \
errno exit fieldwdth forcenum \
fpat1 fpat2 fpat3 fpat4 fpat5 fpat6 fpat7 fpat8 fpat9 fpatnull \
- fsfwfs funlen functab1 functab2 functab3 \
+ fsfwfs funlen functab1 functab2 functab3 functab6 \
fwtest fwtest2 fwtest3 fwtest4 fwtest5 fwtest6 fwtest7 fwtest8 \
genpot gensub gensub2 gensub3 getlndir gnuops2 gnuops3 gnureops gsubind \
icasefs icasers id igncdym igncfs ignrcas2 ignrcas4 ignrcase incdupe \
@@ -1501,7 +1502,7 @@ SHLIB_TESTS = \
testext time
# List of the tests which should be run with --debug option:
-NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3 symtab10
+NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3
# List of the tests which should be run with --lint option:
NEED_LINT = \
diff --git a/test/Makefile.in b/test/Makefile.in
index 3a8381c8..01c9bcc1 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -683,6 +683,8 @@ EXTRA_DIST = \
functab4.ok \
functab5.awk \
functab5.ok \
+ functab6.awk \
+ functab6.ok \
funlen.awk \
funlen.in \
funlen.ok \
@@ -1543,7 +1545,6 @@ EXTRA_DIST = \
symtab9.awk \
symtab9.ok \
symtab10.awk \
- symtab10.in \
symtab10.ok \
symtab11.awk \
symtab11.ok \
@@ -1708,7 +1709,7 @@ GAWK_EXT_TESTS = \
devfd devfd1 devfd2 dfacheck1 dumpvars \
errno exit fieldwdth forcenum \
fpat1 fpat2 fpat3 fpat4 fpat5 fpat6 fpat7 fpat8 fpat9 fpatnull \
- fsfwfs funlen functab1 functab2 functab3 \
+ fsfwfs funlen functab1 functab2 functab3 functab6 \
fwtest fwtest2 fwtest3 fwtest4 fwtest5 fwtest6 fwtest7 fwtest8 \
genpot gensub gensub2 gensub3 getlndir gnuops2 gnuops3 gnureops gsubind \
icasefs icasers id igncdym igncfs ignrcas2 ignrcas4 ignrcase incdupe \
@@ -1761,7 +1762,7 @@ SHLIB_TESTS = \
# List of the tests which should be run with --debug option:
-NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3 symtab10
+NEED_DEBUG = dbugtypedre1 dbugtypedre2 dbugeval2 dbugeval3
# List of the tests which should be run with --lint option:
NEED_LINT = \
@@ -4438,6 +4439,11 @@ functab3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+functab6:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
fwtest:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@@ -4990,7 +4996,7 @@ symtab7:
symtab10:
@echo $@
- @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
symtab11:
diff --git a/test/Maketests b/test/Maketests
index a1062736..5558ae7f 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -1497,6 +1497,11 @@ functab3:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+functab6:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
fwtest:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@@ -2049,7 +2054,7 @@ symtab7:
symtab10:
@echo $@
- @AWKPATH="$(srcdir)" $(AWK) -f $@.awk --debug < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
symtab11:
diff --git a/test/functab6.awk b/test/functab6.awk
new file mode 100644
index 00000000..ec690d0e
--- /dev/null
+++ b/test/functab6.awk
@@ -0,0 +1 @@
+BEGIN { print FUNCTAB[0] }
diff --git a/test/functab6.ok b/test/functab6.ok
new file mode 100644
index 00000000..171a6561
--- /dev/null
+++ b/test/functab6.ok
@@ -0,0 +1,2 @@
+gawk: functab6.awk:1: fatal: reference to uninitialized element `FUNCTAB["0"] is not allowed'
+EXIT CODE: 2
diff --git a/test/symtab10.in b/test/symtab10.in
deleted file mode 100644
index d9afcd66..00000000
--- a/test/symtab10.in
+++ /dev/null
@@ -1,4 +0,0 @@
-watch y
-run
-watch x
-continue
diff --git a/test/symtab10.ok b/test/symtab10.ok
index 9ab38556..8132222d 100644
--- a/test/symtab10.ok
+++ b/test/symtab10.ok
@@ -1,11 +1,2 @@
-Watchpoint 1: y
-Starting program:
-Stopping in BEGIN ...
-Watchpoint 1: y
- Old value: untyped variable
- New value: 1
-main() at `symtab10.awk':1
-1 BEGIN { SYMTAB["x"] ; y=1 ; y++ }
-no symbol `x' in current context
-Program exited normally with exit value: 0
+gawk: symtab10.awk:1: fatal: reference to uninitialized element `SYMTAB["x"] is not allowed'
EXIT CODE: 2