aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--NEWS3
-rw-r--r--doc/ChangeLog6
-rw-r--r--doc/gawk.15
-rw-r--r--doc/gawktexi.in8
-rw-r--r--interpret.h32
-rw-r--r--test/Makefile.am3
-rw-r--r--test/Makefile.in3
-rw-r--r--test/symtab6.ok30
-rw-r--r--test/symtab7.ok4
9 files changed, 41 insertions, 53 deletions
diff --git a/NEWS b/NEWS
index a25c30d7..b543b0fe 100644
--- a/NEWS
+++ b/NEWS
@@ -18,6 +18,9 @@ Changes from 4.2.x to 5.0.0
4. PROCINFO["platform"] yields a string indicating the platform for
which gawk was compiled.
+5. Writing to elements of SYMTAB that are not variable names now
+ causes a fatal error.
+
Changes from 4.2.1 to 4.2.2
---------------------------
diff --git a/doc/ChangeLog b/doc/ChangeLog
index f31aae7f..261388a2 100644
--- a/doc/ChangeLog
+++ b/doc/ChangeLog
@@ -1,3 +1,9 @@
+2018-11-29 Arnold D. Robbins <arnold@skeeve.com>
+
+ * gawktexi.in (Auto-set): Document that you can no longer use
+ arbitrary indices in SYMTAB.
+ * gawk.1: Ditto.
+
2018-11-27 Arnold D. Robbins <arnold@skeeve.com>
* gawktexi.in (Other Versions): Document GoAWK, an awk interpreter
diff --git a/doc/gawk.1 b/doc/gawk.1
index 5caff79b..4964cb3d 100644
--- a/doc/gawk.1
+++ b/doc/gawk.1
@@ -13,7 +13,7 @@
. if \w'\(rq' .ds rq "\(rq
. \}
.\}
-.TH GAWK 1 "Nov 26 2018" "Free Software Foundation" "Utility Commands"
+.TH GAWK 1 "Nov 29 2018" "Free Software Foundation" "Utility Commands"
.SH NAME
gawk \- pattern scanning and processing language
.SH SYNOPSIS
@@ -1425,7 +1425,8 @@ You may not use the
.B delete
statement with the
.B SYMTAB
-array.
+array, nor assign to elements with an index that is
+not a variable name.
.TP
.B TEXTDOMAIN
The text domain of the \*(AK program; used to find the localized
diff --git a/doc/gawktexi.in b/doc/gawktexi.in
index 9a21913b..cc667534 100644
--- a/doc/gawktexi.in
+++ b/doc/gawktexi.in
@@ -15253,7 +15253,8 @@ if an element in @code{SYMTAB} is an array.
Also, you may not use the @code{delete} statement with the
@code{SYMTAB} array.
-You may use an index for @code{SYMTAB} that is not a predefined identifier:
+Prior to @value{PVERSION} 5.0 of @command{gawk}, you could
+use an index for @code{SYMTAB} that was not a predefined identifier:
@example
SYMTAB["xxx"] = 5
@@ -15261,9 +15262,8 @@ print SYMTAB["xxx"]
@end example
@noindent
-This works as expected: in this case @code{SYMTAB} acts just like
-a regular array. The only difference is that you can't then delete
-@code{SYMTAB["xxx"]}.
+This no longer works, instead producing a fatal error, as it led
+to rampant confusion.
@cindex Schorr, Andrew
The @code{SYMTAB} array is more interesting than it looks. Andrew Schorr
diff --git a/interpret.h b/interpret.h
index 4381a929..6a1a08b4 100644
--- a/interpret.h
+++ b/interpret.h
@@ -348,16 +348,19 @@ uninitialized_scalar:
* 3. Values that awk code stuck into SYMTAB not related to variables (Node_value)
* For 1, since we are giving it a value, we have to change the type to Node_var.
* For 1 and 2, we have to step through the Node_var to get to the value.
- * For 3, we just us the value we got from assoc_lookup(), above.
+ * For 3, we fatal out. This avoids confusion on things like
+ * SYMTAB["a foo"] = 42 # variable with a space in its name?
*/
if (t1 == func_table)
fatal(_("cannot assign to elements of FUNCTAB"));
- else if ( t1 == symbol_table
- && ( (*lhs)->type == Node_var
+ else if (t1 == symbol_table) {
+ if (( (*lhs)->type == Node_var
|| (*lhs)->type == Node_var_new)) {
- update_global_values(); /* make sure stuff like NF, NR, are up to date */
- (*lhs)->type = Node_var; /* in case was Node_var_new */
- lhs = & ((*lhs)->var_value); /* extra level of indirection */
+ update_global_values(); /* make sure stuff like NF, NR, are up to date */
+ (*lhs)->type = Node_var; /* in case was Node_var_new */
+ lhs = & ((*lhs)->var_value); /* extra level of indirection */
+ } else
+ fatal(_("cannot assign to arbitrary elements of SYMTAB"));
}
assert(set_idx == NULL);
@@ -658,22 +661,25 @@ mod:
/*
* Changing something in FUNCTAB is not allowed.
*
- * SYMTAB is a little more messy. Three kinds of values may
- * be stored in SYMTAB:
+ * SYMTAB is a little more messy. Three possibilities for SYMTAB:
* 1. Variables that don"t yet have a value (Node_var_new)
* 2. Variables that have a value (Node_var)
* 3. Values that awk code stuck into SYMTAB not related to variables (Node_value)
* For 1, since we are giving it a value, we have to change the type to Node_var.
* For 1 and 2, we have to step through the Node_var to get to the value.
- * For 3, we just us the value we got from assoc_lookup(), above.
+ * For 3, we fatal out. This avoids confusion on things like
+ * SYMTAB["a foo"] = 42 # variable with a space in its name?
*/
if (t1 == func_table)
fatal(_("cannot assign to elements of FUNCTAB"));
- else if ( t1 == symbol_table
- && ( (*lhs)->type == Node_var
+ else if (t1 == symbol_table) {
+ if (( (*lhs)->type == Node_var
|| (*lhs)->type == Node_var_new)) {
- (*lhs)->type = Node_var; /* in case was Node_var_new */
- lhs = & ((*lhs)->var_value); /* extra level of indirection */
+ update_global_values(); /* make sure stuff like NF, NR, are up to date */
+ (*lhs)->type = Node_var; /* in case was Node_var_new */
+ lhs = & ((*lhs)->var_value); /* extra level of indirection */
+ } else
+ fatal(_("cannot assign to arbitrary elements of SYMTAB"));
}
unref(*lhs);
diff --git a/test/Makefile.am b/test/Makefile.am
index e1ecc649..a44a1944 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -2101,8 +2101,7 @@ charasbytes:
symtab6:
@echo $@
- @$(AWK) -d__$@ -f "$(srcdir)"/$@.awk
- @grep -v '^ENVIRON' __$@ | grep -v '^PROCINFO' > _$@ ; rm __$@
+ @$(AWK) -f "$(srcdir)"/$@.awk > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
symtab8:
diff --git a/test/Makefile.in b/test/Makefile.in
index 1e3fe2ee..4c195884 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -2549,8 +2549,7 @@ charasbytes:
symtab6:
@echo $@
- @$(AWK) -d__$@ -f "$(srcdir)"/$@.awk
- @grep -v '^ENVIRON' __$@ | grep -v '^PROCINFO' > _$@ ; rm __$@
+ @$(AWK) -f "$(srcdir)"/$@.awk > _$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
symtab8:
diff --git a/test/symtab6.ok b/test/symtab6.ok
index 7de717a0..23a1633d 100644
--- a/test/symtab6.ok
+++ b/test/symtab6.ok
@@ -1,28 +1,2 @@
-ARGC: 1
-ARGIND: 0
-ARGV: array, 1 elements
-BINMODE: 0
-CONVFMT: "%.6g"
-ERRNO: ""
-FIELDWIDTHS: ""
-FILENAME: ""
-FNR: 0
-FPAT: "[^[:space:]]+"
-FS: " "
-FUNCTAB: array, 41 elements
-IGNORECASE: 0
-LINT: 0
-NF: 0
-NR: 0
-OFMT: "%.6g"
-OFS: " "
-ORS: "\n"
-PREC: 53
-RLENGTH: 0
-ROUNDMODE: "N"
-RS: "\n"
-RSTART: 0
-RT: ""
-SUBSEP: "\034"
-SYMTAB: array, 29 elements
-TEXTDOMAIN: "messages"
+gawk: ./symtab6.awk:1: fatal: cannot assign to arbitrary elements of SYMTAB
+EXIT CODE: 2
diff --git a/test/symtab7.ok b/test/symtab7.ok
index 28328831..37de1a49 100644
--- a/test/symtab7.ok
+++ b/test/symtab7.ok
@@ -1,2 +1,2 @@
-30
-40
+gawk: symtab7.awk:4: (FILENAME=- FNR=1) fatal: cannot assign to arbitrary elements of SYMTAB
+EXIT CODE: 2