diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2022-04-28 08:39:20 +0300 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2022-04-28 08:39:20 +0300 |
commit | 4afcd655d827cc095e20abbf05b4aa5d41122600 (patch) | |
tree | 6f9e5e49855085e29b7335c713577bdf7ffd5a72 | |
parent | 0171cdeb5ce6f0d43bc41b0a69d706d367370bd0 (diff) | |
download | gawk-4afcd655d827cc095e20abbf05b4aa5d41122600.tar.gz |
Make SYMTAB["x"]["y"] a fatal error also.
-rw-r--r-- | ChangeLog | 6 | ||||
-rw-r--r-- | interpret.h | 18 | ||||
-rw-r--r-- | pc/ChangeLog | 4 | ||||
-rw-r--r-- | pc/Makefile.tst | 6 | ||||
-rw-r--r-- | test/ChangeLog | 5 | ||||
-rw-r--r-- | test/Makefile.am | 3 | ||||
-rw-r--r-- | test/Makefile.in | 8 | ||||
-rw-r--r-- | test/Maketests | 5 | ||||
-rw-r--r-- | test/symtab12.awk | 7 | ||||
-rw-r--r-- | test/symtab12.ok | 32 |
10 files changed, 94 insertions, 0 deletions
@@ -1,3 +1,9 @@ +2022-04-28 Arnold D. Robbins <arnold@skeeve.com> + + Disallow SYMTAB["x"]["y"]. Reported by Jason C. Kwan. + + * interpret.h (r_interpret): Add checks at Op_sub_array case. + 2022-04-21 Arnold D. Robbins <arnold@skeeve.com> Fix some profiling issues related to comments in switch / case diff --git a/interpret.h b/interpret.h index 03adcd79..bda9a01e 100644 --- a/interpret.h +++ b/interpret.h @@ -329,6 +329,24 @@ uninitialized_scalar: t2 = mk_sub(pc->sub_count); t1 = POP_ARRAY(false); r = in_array(t1, t2); + + if (r == NULL) { + t2 = force_string(t2); + + 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)); + } + } + if (r == NULL) { r = make_array(); r->parent_array = t1; diff --git a/pc/ChangeLog b/pc/ChangeLog index 814eee19..d2e6a846 100644 --- a/pc/ChangeLog +++ b/pc/ChangeLog @@ -1,3 +1,7 @@ +2022-04-28 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.tst: Regenerated. + 2022-04-27 Arnold D. Robbins <arnold@skeeve.com> * Makefile.tst: Regenerated. diff --git a/pc/Makefile.tst b/pc/Makefile.tst index 03081946..13971a0f 100644 --- a/pc/Makefile.tst +++ b/pc/Makefile.tst @@ -217,6 +217,7 @@ GAWK_EXT_TESTS = \ strftime strtonum strtonum1 stupid1 stupid2 stupid3 stupid4 stupid5 \ switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 symtab7 \ symtab8 symtab9 symtab10 symtab11 timeout typedregex1 typedregex2 \ + symtab12 \ typedregex3 typedregex4 typedregex5 typedregex6 typeof1 typeof2 \ typeof3 typeof4 typeof5 typeof6 watchpoint1 @@ -3386,6 +3387,11 @@ typedregex2: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +symtab12: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + typedregex3: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/ChangeLog b/test/ChangeLog index 91ed0ece..142f8d2d 100644 --- a/test/ChangeLog +++ b/test/ChangeLog @@ -1,3 +1,8 @@ +2022-04-28 Arnold D. Robbins <arnold@skeeve.com> + + * Makefile.am (EXTRA_DIST): symtab12, new test. + * symtab12.awk, symtab12.ok: New files. + 2022-04-27 Arnold D. Robbins <arnold@skeeve.com> * Makefile.am (EXTRA_DIST): regex3minus, new test. diff --git a/test/Makefile.am b/test/Makefile.am index 3c949a49..33fd4317 100644 --- a/test/Makefile.am +++ b/test/Makefile.am @@ -1300,6 +1300,8 @@ EXTRA_DIST = \ symtab10.ok \ symtab11.awk \ symtab11.ok \ + symtab12.awk \ + symtab12.ok \ synerr1.awk \ synerr1.ok \ synerr2.awk \ @@ -1480,6 +1482,7 @@ GAWK_EXT_TESTS = \ strftime strtonum strtonum1 stupid1 stupid2 stupid3 stupid4 stupid5 \ switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 symtab7 \ symtab8 symtab9 symtab10 symtab11 timeout typedregex1 typedregex2 \ + symtab12 \ typedregex3 typedregex4 typedregex5 typedregex6 typeof1 typeof2 \ typeof3 typeof4 typeof5 typeof6 watchpoint1 diff --git a/test/Makefile.in b/test/Makefile.in index ac649b34..5d6f9107 100644 --- a/test/Makefile.in +++ b/test/Makefile.in @@ -1566,6 +1566,8 @@ EXTRA_DIST = \ symtab10.ok \ symtab11.awk \ symtab11.ok \ + symtab12.awk \ + symtab12.ok \ synerr1.awk \ synerr1.ok \ synerr2.awk \ @@ -1746,6 +1748,7 @@ GAWK_EXT_TESTS = \ strftime strtonum strtonum1 stupid1 stupid2 stupid3 stupid4 stupid5 \ switch2 symtab1 symtab2 symtab3 symtab4 symtab5 symtab6 symtab7 \ symtab8 symtab9 symtab10 symtab11 timeout typedregex1 typedregex2 \ + symtab12 \ typedregex3 typedregex4 typedregex5 typedregex6 typeof1 typeof2 \ typeof3 typeof4 typeof5 typeof6 watchpoint1 @@ -5072,6 +5075,11 @@ typedregex2: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +symtab12: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + typedregex3: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/Maketests b/test/Maketests index 6af82092..9ab86f00 100644 --- a/test/Maketests +++ b/test/Maketests @@ -2112,6 +2112,11 @@ typedregex2: @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ +symtab12: + @echo $@ + @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ + @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@ + typedregex3: @echo $@ @-AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@ diff --git a/test/symtab12.awk b/test/symtab12.awk new file mode 100644 index 00000000..cc3d19dd --- /dev/null +++ b/test/symtab12.awk @@ -0,0 +1,7 @@ +BEGIN { + for (i in SYMTAB) + print i | "sort" + close("sort") + print "----" + SYMTAB["foofoo"]["q"] = "q" +} diff --git a/test/symtab12.ok b/test/symtab12.ok new file mode 100644 index 00000000..b0b7b0ea --- /dev/null +++ b/test/symtab12.ok @@ -0,0 +1,32 @@ +ARGC +ARGIND +ARGV +BINMODE +CONVFMT +ENVIRON +ERRNO +FIELDWIDTHS +FILENAME +FNR +FPAT +FS +IGNORECASE +LINT +NF +NR +OFMT +OFS +ORS +PREC +PROCINFO +RLENGTH +ROUNDMODE +RS +RSTART +RT +SUBSEP +TEXTDOMAIN +i +---- +gawk: symtab12.awk:6: fatal: reference to uninitialized element `SYMTAB["foofoo"] is not allowed' +EXIT CODE: 2 |