aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog14
-rw-r--r--awk.h2
-rw-r--r--str_array.c22
3 files changed, 26 insertions, 12 deletions
diff --git a/ChangeLog b/ChangeLog
index 0f0e8949..1d1bc935 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,7 +1,17 @@
+2016-05-26 Arnold D. Robbins <arnold@skeeve.com>
+
+ * awk.h [fatal]: Make parentheses and use of indirection
+ consistent with warning and lintwarn. Thanks to Andrew Schorr
+ for pointing this out.
+ * str_array.c (str_lookup): Move test for MAYBE_NUM to where
+ we duplicate the subscript. Removing it across the board is
+ wrong if there are multiple references to the value. Thanks
+ to Andrew Schorr for discussion and test case.
+
2016-05-26 Andrew J. Schorr <aschorr@telemetry-investments.com>
- * awk.h (get_actual_argument): Add an initial argument containing the
- (NODE *) previously returned by get_argument. This allows us to
+ * awk.h (get_actual_argument): Add an initial argument containing
+ the (NODE *) previously returned by get_argument. This allows us to
eliminate a call to get_argument from inside get_actual_argument.
(get_scalar_argument, get_array_argument): Change macro definition to
add an initial node argument to pass through to get_actual_argument.
diff --git a/awk.h b/awk.h
index 8a25dcc7..213651de 100644
--- a/awk.h
+++ b/awk.h
@@ -1278,7 +1278,7 @@ DEREF(NODE *r)
#define efree(p) free(p)
-#define fatal set_loc(__FILE__, __LINE__), r_fatal
+#define fatal (*(set_loc(__FILE__, __LINE__), r_fatal))
extern jmp_buf fatal_tag;
extern bool fatal_tag_valid;
diff --git a/str_array.c b/str_array.c
index c122ab94..7a6b50fe 100644
--- a/str_array.c
+++ b/str_array.c
@@ -156,7 +156,18 @@ str_lookup(NODE *symbol, NODE *subs)
hash1 = code1 % (unsigned long) symbol->array_size;
}
- if (subs->stfmt != -1) {
+
+ /*
+ * Repeat after me: "Array indices are always strings."
+ * "Array indices are always strings."
+ * "Array indices are always strings."
+ * "Array indices are always strings."
+ * ....
+ * If subs is a STRNUM, copy it; don't clear the MAYBE_NUM
+ * flag on it since other variables could be using the same
+ * reference-counted value.
+ */
+ if (subs->stfmt != -1 || (subs->flags & MAYBE_NUM) != 0) {
NODE *tmp;
/*
@@ -187,14 +198,7 @@ str_lookup(NODE *symbol, NODE *subs)
subs = dupnode(subs);
}
- /*
- * Repeat after me: "Array indices are always strings."
- * "Array indices are always strings."
- * "Array indices are always strings."
- * "Array indices are always strings."
- * ....
- */
- subs->flags &= ~MAYBE_NUM;
+ assert((subs->flags & MAYBE_NUM) == 0);
getbucket(b);
b->ahnext = symbol->buckets[hash1];