aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog6
-rw-r--r--str_array.c9
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am2
-rw-r--r--test/Makefile.in7
-rw-r--r--test/Maketests5
-rw-r--r--test/aryunasgn.awk17
-rw-r--r--test/aryunasgn.ok8
8 files changed, 55 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 10bf0872..3a05ca56 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -2,6 +2,12 @@
* main.c (usage): Add URL for Bug reporting info to the help message.
+ Unrelated:
+
+ * str_array.c (str_lookup): Make a copy of the string if it
+ came from Nnull_string or a null field. Thanks to
+ Daniel Pettet for the report.
+
2017-08-04 Arnold D. Robbins <arnold@skeeve.com>
* array.c, awk.h, awkgram.y, builtin.c, cint_array.c,
diff --git a/str_array.c b/str_array.c
index 55e90497..8d6d2b01 100644
--- a/str_array.c
+++ b/str_array.c
@@ -165,8 +165,13 @@ str_lookup(NODE *symbol, NODE *subs)
* "Array indices are always strings."
* ....
*/
- if (subs->stfmt != STFMT_UNUSED) {
- /* The string was generated using CONVFMT. */
+ // Special cases:
+ // 1. The string was generated using CONVFMT.
+ // 2. The string was from an unassigned variable.
+ // 3. The string was from an unassigned field.
+ if ( subs->stfmt != STFMT_UNUSED
+ || subs == Nnull_string
+ || (subs->flags & NULL_FIELD) != 0) {
NODE *tmp;
/*
diff --git a/test/ChangeLog b/test/ChangeLog
index b7225ce8..e85aa681 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -2,6 +2,11 @@
* badargs.ok: Update after code changes.
+ Unrelated:
+
+ * Makefile.am (aryunasgn): New test.
+ * aryunasgn.awk, aryunasgn.ok: New files.
+
2017-08-04 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am: Update copyright year.
diff --git a/test/Makefile.am b/test/Makefile.am
index dddcf931..f519b0db 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -1199,7 +1199,7 @@ BASIC_TESTS = \
addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm arrayprm2 arrayprm3 \
arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 arynasty \
arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
- aryprm8 aryprm9 arysubnm asgext awkpath \
+ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \
back89 backgsub badassign1 badbuild \
callparam childin clobber closebad clsflnam compare compare2 concat1 concat2 \
concat3 concat4 concat5 convfmt \
diff --git a/test/Makefile.in b/test/Makefile.in
index 2b21e0a7..a6e4f96e 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -1456,7 +1456,7 @@ BASIC_TESTS = \
addcomma anchgsub anchor argarray arrayind1 arrayind2 arrayind3 arrayparm arrayprm2 arrayprm3 \
arrayref arrymem1 arryref2 arryref3 arryref4 arryref5 arynasty \
arynocls aryprm1 aryprm2 aryprm3 aryprm4 aryprm5 aryprm6 aryprm7 \
- aryprm8 aryprm9 arysubnm asgext awkpath \
+ aryprm8 aryprm9 arysubnm aryunasgn asgext awkpath \
back89 backgsub badassign1 badbuild \
callparam childin clobber closebad clsflnam compare compare2 concat1 concat2 \
concat3 concat4 concat5 convfmt \
@@ -2990,6 +2990,11 @@ arysubnm:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+aryunasgn:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
asgext:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index f8c54f94..e6a2f300 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -130,6 +130,11 @@ arysubnm:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+aryunasgn:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
asgext:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/aryunasgn.awk b/test/aryunasgn.awk
new file mode 100644
index 00000000..ccb3fd23
--- /dev/null
+++ b/test/aryunasgn.awk
@@ -0,0 +1,17 @@
+BEGIN {
+ a[i] = "null" # i is initially undefined
+ for (i in a) { # i is null string
+ print length(i), a[i] # , typeof(i) # 0 null
+ print (i==0), (i=="") # 1 1 should be 0 1
+ }
+ print a[""] # null
+ print a[0] #
+
+ b[$2] = "null also" # $2 is also undefined
+ for (j in b) {
+ print length(j), a[j] # , typeof(i) # 0 null
+ print (j==0), (j=="") # 1 1 should be 0 1
+ }
+ print b[""] # null
+ print b[0] #
+}
diff --git a/test/aryunasgn.ok b/test/aryunasgn.ok
new file mode 100644
index 00000000..798c6de3
--- /dev/null
+++ b/test/aryunasgn.ok
@@ -0,0 +1,8 @@
+0 null
+0 1
+null
+
+0 null
+0 1
+null also
+