diff options
author | Arnold D. Robbins <arnold@skeeve.com> | 2016-05-26 16:22:59 -0400 |
---|---|---|
committer | Arnold D. Robbins <arnold@skeeve.com> | 2016-05-26 16:22:59 -0400 |
commit | 14d958c82b939d26ad37ab0c0debfedf780404d0 (patch) | |
tree | 223f180287ae694773a80206c681bb8b8a0636f6 | |
parent | 2af19378be4e7eeec7754053070cf4bad035d7b1 (diff) | |
download | egawk-14d958c82b939d26ad37ab0c0debfedf780404d0.tar.gz egawk-14d958c82b939d26ad37ab0c0debfedf780404d0.tar.bz2 egawk-14d958c82b939d26ad37ab0c0debfedf780404d0.zip |
Further fix for MAYBE_NUM values used as array subscripts.
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | str_array.c | 22 |
2 files changed, 17 insertions, 9 deletions
@@ -3,6 +3,10 @@ * 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> diff --git a/str_array.c b/str_array.c index 9514d515..1de432c7 100644 --- a/str_array.c +++ b/str_array.c @@ -137,7 +137,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; /* @@ -168,14 +179,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]; |