summaryrefslogtreecommitdiff
path: root/sys/src/cmd/awk
diff options
context:
space:
mode:
authorOri Bernstein <ori@eigenstate.org>2022-06-25 20:03:41 +0000
committerOri Bernstein <ori@eigenstate.org>2022-06-25 20:03:41 +0000
commit10afa189d5ee84e1935ead905b3bbe38060a92e8 (patch)
treeda981117a100864d0697e13453a9f79de557cde1 /sys/src/cmd/awk
parent5579176f4a885bb83119bb49598c357ce8db2343 (diff)
awk: correct incoherent cell in assignment (thanks smj, mpinjr)
In run.c::assign(), assigning to $0 from $F, a field, where F >= 2, produces an incoherent cell. The assignment occurs in two steps, first the string value and then the float. When the string value is assigned to $0, setsval invalidates the fields. If FS hasn't changed, after getfval rebuilds the fields, NF = 1 and F >= 2, therefore $F is definitely uninitialized. The result is a float val of 0.0, producing a boolean false in the pattern expression. Coercing a string comparison gives the expected result because the incoherent cell has the correct string value, which is not empty and evaluates to true.
Diffstat (limited to 'sys/src/cmd/awk')
-rw-r--r--sys/src/cmd/awk/run.c3
1 files changed, 2 insertions, 1 deletions
diff --git a/sys/src/cmd/awk/run.c b/sys/src/cmd/awk/run.c
index 5e75c9d0a..090410314 100644
--- a/sys/src/cmd/awk/run.c
+++ b/sys/src/cmd/awk/run.c
@@ -1127,8 +1127,9 @@ Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */
if (x == y && !(x->tval & (FLD|REC))) /* self-assignment: */
goto Free; /* leave alone unless it's a field */
if ((y->tval & (STR|NUM)) == (STR|NUM)) {
+ yf = getfval(y);
setsval(x, getsval(y));
- x->fval = getfval(y);
+ x->fval = yf;
x->tval |= NUM;
}
else if (isstr(y))