From 6315525dbef08bac66b6369f7d6952b67b5adcba Mon Sep 17 00:00:00 2001 From: Cody Peter Mello Date: Sun, 23 Sep 2018 17:59:52 -0700 Subject: [PATCH] Rebuild fields when NF is assigned to itself --- bugs-fixed/README | 2 ++ bugs-fixed/nf-self-assign.awk | 6 ++++++ bugs-fixed/nf-self-assign.bad | 1 + bugs-fixed/nf-self-assign.ok | 1 + run.c | 4 ++-- 5 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 bugs-fixed/nf-self-assign.awk create mode 100644 bugs-fixed/nf-self-assign.bad create mode 100644 bugs-fixed/nf-self-assign.ok diff --git a/bugs-fixed/README b/bugs-fixed/README index 222ef68..29c845f 100644 --- a/bugs-fixed/README +++ b/bugs-fixed/README @@ -23,3 +23,5 @@ and also if CONVFMT changed. 7. unary-plus: Unary plus on a string constant returned the string. Instead, it should convert the value to numeric and give that value. + +X. nf-self-assign: "NF = NF" wouldn't force the record to be rebuilt. diff --git a/bugs-fixed/nf-self-assign.awk b/bugs-fixed/nf-self-assign.awk new file mode 100644 index 0000000..6ae29ee --- /dev/null +++ b/bugs-fixed/nf-self-assign.awk @@ -0,0 +1,6 @@ +BEGIN { + $0="a b c"; + OFS=","; + NF = NF; + print; +} diff --git a/bugs-fixed/nf-self-assign.bad b/bugs-fixed/nf-self-assign.bad new file mode 100644 index 0000000..3774da6 --- /dev/null +++ b/bugs-fixed/nf-self-assign.bad @@ -0,0 +1 @@ +a b c diff --git a/bugs-fixed/nf-self-assign.ok b/bugs-fixed/nf-self-assign.ok new file mode 100644 index 0000000..b2ffb02 --- /dev/null +++ b/bugs-fixed/nf-self-assign.ok @@ -0,0 +1 @@ +a,b,c diff --git a/run.c b/run.c index 81b75da..14a0c74 100644 --- a/run.c +++ b/run.c @@ -1117,8 +1117,8 @@ Cell *assign(Node **a, int n) /* a[0] = a[1], a[0] += a[1], etc. */ y = execute(a[1]); x = execute(a[0]); if (n == ASSIGN) { /* ordinary assignment */ - if (x == y && !(x->tval & (FLD|REC))) /* self-assignment: */ - ; /* leave alone unless it's a field */ + if (x == y && !(x->tval & (FLD|REC)) && x != nfloc) + ; /* self-assignment: leave alone unless it's a field or NF */ else if ((y->tval & (STR|NUM)) == (STR|NUM)) { setsval(x, getsval(y)); x->fval = getfval(y);