aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorArnold D. Robbins <arnold@skeeve.com>2013-09-13 15:37:25 +0300
committerArnold D. Robbins <arnold@skeeve.com>2013-09-13 15:37:25 +0300
commit2fcffaeee37416708fab505209a55ddd32846463 (patch)
tree1d31315cc63b8eae764d07e381d592e6bf9ac2b3
parent1812b4752c0a2e8c5ec693eb3cd1c866a9952a2f (diff)
downloadegawk-2fcffaeee37416708fab505209a55ddd32846463.tar.gz
egawk-2fcffaeee37416708fab505209a55ddd32846463.tar.bz2
egawk-2fcffaeee37416708fab505209a55ddd32846463.zip
Fix problem when extending NF. See test/nfloop.
-rw-r--r--ChangeLog14
-rw-r--r--awk.h1
-rw-r--r--builtin.c2
-rw-r--r--eval.c2
-rw-r--r--field.c11
-rw-r--r--test/ChangeLog5
-rw-r--r--test/Makefile.am4
-rw-r--r--test/Makefile.in9
-rw-r--r--test/Maketests5
-rw-r--r--test/nfloop.awk8
-rw-r--r--test/nfloop.ok1
11 files changed, 56 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index d80680f3..84d217da 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,17 @@
+2013-09-13 Arnold D. Robbins <arnold@skeeve.com>
+
+ Fix use of NF after it's extended, e.g. see test/nfloop.awk.
+
+ * awk.h (NULL_FIELD): New flag
+ * builtin.c (do_print_rec): Check f0->flags instead of if
+ equal to Nnull_string.
+ * eval.c (r_get_field): Check (*lhs)->flags instead of if
+ equal to Nnull_string or Null_field.
+ * field.c (init_fields): Init field zero and Null_field with
+ NULL_FIELD flag.
+ (set_NF): Set parse_high_water = NF in case NF extended past the
+ end. This is the actual bug fix.
+
2013-09-08 Arnold D. Robbins <arnold@skeeve.com>
Fixes based on reports from a static code checker. Thanks to
diff --git a/awk.h b/awk.h
index bb2f2054..f57e62e9 100644
--- a/awk.h
+++ b/awk.h
@@ -434,6 +434,7 @@ typedef struct exp_node {
# define MPFN 0x0800 /* arbitrary-precision floating-point number */
# define MPZN 0x1000 /* arbitrary-precision integer */
# define NO_EXT_SET 0x2000 /* extension cannot set a value for this variable */
+# define NULL_FIELD 0x4000 /* this is the null field */
/* type = Node_var_array */
# define ARRAYMAXED 0x4000 /* array is at max size */
diff --git a/builtin.c b/builtin.c
index eb823ac1..9258ea60 100644
--- a/builtin.c
+++ b/builtin.c
@@ -2159,7 +2159,7 @@ do_print_rec(int nargs, int redirtype)
f0 = fields_arr[0];
- if (do_lint && f0 == Nnull_string)
+ if (do_lint && (f0->flags & NULL_FIELD) != 0)
lintwarn(_("reference to uninitialized field `$%d'"), 0);
efwrite(f0->stptr, sizeof(char), f0->stlen, fp, "print", rp, false);
diff --git a/eval.c b/eval.c
index cf2264bf..789832d0 100644
--- a/eval.c
+++ b/eval.c
@@ -1180,7 +1180,7 @@ r_get_field(NODE *n, Func_ptr *assign, bool reference)
*assign = reset_record;
} else
lhs = get_field(field_num, assign);
- if (do_lint && reference && (*lhs == Null_field || *lhs == Nnull_string))
+ if (do_lint && reference && ((*lhs)->flags & NULL_FIELD) != 0)
lintwarn(_("reference to uninitialized field `$%ld'"),
field_num);
return lhs;
diff --git a/field.c b/field.c
index 3cd66067..0a7cee8f 100644
--- a/field.c
+++ b/field.c
@@ -85,13 +85,19 @@ void
init_fields()
{
emalloc(fields_arr, NODE **, sizeof(NODE *), "init_fields");
- fields_arr[0] = dupnode(Nnull_string);
+
+ getnode(fields_arr[0]);
+ *fields_arr[0] = *Nnull_string;
+ fields_arr[0]->flags |= NULL_FIELD;
+
parse_extent = fields_arr[0]->stptr;
save_FS = dupnode(FS_node->var_value);
+
getnode(Null_field);
*Null_field = *Nnull_string;
Null_field->valref = 1;
- Null_field->flags = (FIELD|STRCUR|STRING);
+ Null_field->flags = (FIELD|STRCUR|STRING|NULL_FIELD);
+
field0_valid = true;
}
@@ -348,6 +354,7 @@ set_NF()
*n = *Null_field;
fields_arr[i] = n;
}
+ parse_high_water = NF;
} else if (parse_high_water > 0) {
for (i = NF + 1; i >= 0 && i <= parse_high_water; i++) {
unref(fields_arr[i]);
diff --git a/test/ChangeLog b/test/ChangeLog
index 15166f2f..ad0366f2 100644
--- a/test/ChangeLog
+++ b/test/ChangeLog
@@ -3,6 +3,11 @@
* Makefile.am: Fix quoting for generation of Maketests file so
that it will happen correctly.
+ Unrelated:
+
+ * Makefile.am (nfloop): New test.
+ * nfloop.awk, nfloop.ok: New files.
+
2013-08-15 Arnold D. Robbins <arnold@skeeve.com>
* Makefile.am: Quote $(srcdir) everywhere so that tests can run
diff --git a/test/Makefile.am b/test/Makefile.am
index bbb0354c..8288cf7d 100644
--- a/test/Makefile.am
+++ b/test/Makefile.am
@@ -540,6 +540,8 @@ EXTRA_DIST = \
nfldstr.awk \
nfldstr.in \
nfldstr.ok \
+ nfloop.awk \
+ nfloop.ok \
nfneg.awk \
nfneg.ok \
nfset.awk \
@@ -943,7 +945,7 @@ BASIC_TESTS = \
inputred intest intprec iobug1 \
leaddig leadnl litoct longsub longwrds \
manglprm math membug1 messages minusstr mmap8k mtchi18n \
- nasty nasty2 negexp negrange nested nfldstr nfneg nfset nlfldsep \
+ nasty nasty2 negexp negrange nested nfldstr nfloop nfneg nfset nlfldsep \
nlinstr nlstrina noeffect nofile nofmtch noloop1 noloop2 nonl \
noparms nors nulrsend numindex numsubstr \
octsub ofmt ofmta ofmtbig ofmtfidl ofmts ofs1 onlynl opasnidx opasnslf \
diff --git a/test/Makefile.in b/test/Makefile.in
index 959ef3e0..31a22602 100644
--- a/test/Makefile.in
+++ b/test/Makefile.in
@@ -758,6 +758,8 @@ EXTRA_DIST = \
nfldstr.awk \
nfldstr.in \
nfldstr.ok \
+ nfloop.awk \
+ nfloop.ok \
nfneg.awk \
nfneg.ok \
nfset.awk \
@@ -1160,7 +1162,7 @@ BASIC_TESTS = \
inputred intest intprec iobug1 \
leaddig leadnl litoct longsub longwrds \
manglprm math membug1 messages minusstr mmap8k mtchi18n \
- nasty nasty2 negexp negrange nested nfldstr nfneg nfset nlfldsep \
+ nasty nasty2 negexp negrange nested nfldstr nfloop nfneg nfset nlfldsep \
nlinstr nlstrina noeffect nofile nofmtch noloop1 noloop2 nonl \
noparms nors nulrsend numindex numsubstr \
octsub ofmt ofmta ofmtbig ofmtfidl ofmts ofs1 onlynl opasnidx opasnslf \
@@ -2721,6 +2723,11 @@ nfldstr:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+nfloop:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
nfneg:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/Maketests b/test/Maketests
index 1f3daf76..a1791a92 100644
--- a/test/Maketests
+++ b/test/Maketests
@@ -470,6 +470,11 @@ nfldstr:
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk < "$(srcdir)"/$@.in >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
@-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+nfloop:
+ @echo $@
+ @AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
+ @-$(CMP) "$(srcdir)"/$@.ok _$@ && rm -f _$@
+
nfneg:
@echo $@
@AWKPATH="$(srcdir)" $(AWK) -f $@.awk >_$@ 2>&1 || echo EXIT CODE: $$? >>_$@
diff --git a/test/nfloop.awk b/test/nfloop.awk
new file mode 100644
index 00000000..c37700ac
--- /dev/null
+++ b/test/nfloop.awk
@@ -0,0 +1,8 @@
+BEGIN {
+ $0 = "aaa"
+ NF = 10
+ for (j = 2; j <= NF; ++j) {
+ $j = "_"
+ }
+ print
+}
diff --git a/test/nfloop.ok b/test/nfloop.ok
new file mode 100644
index 00000000..cc683eae
--- /dev/null
+++ b/test/nfloop.ok
@@ -0,0 +1 @@
+aaa _ _ _ _ _ _ _ _ _