Print an error message for negative NF values

This commit is contained in:
Cody Peter Mello 2018-09-25 21:19:49 -07:00
parent 6315525dbe
commit 179536a516
4 changed files with 7 additions and 0 deletions

View File

@ -25,3 +25,5 @@ and also if CONVFMT changed.
Instead, it should convert the value to numeric and give that value. 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. X. nf-self-assign: "NF = NF" wouldn't force the record to be rebuilt.
X. negative-nf: Setting NF to a negative value caused a segmentation fault.

View File

@ -0,0 +1 @@
BEGIN { NF = -5; }

View File

@ -0,0 +1,2 @@
./a.out: cannot set NF to a negative value
source line number 1

2
lib.c
View File

@ -390,6 +390,8 @@ void newfld(int n) /* add field n after end of existing lastfld */
void setlastfld(int n) /* set lastfld cleaning fldtab cells if necessary */ void setlastfld(int n) /* set lastfld cleaning fldtab cells if necessary */
{ {
if (n < 0)
FATAL("cannot set NF to a negative value");
if (n > nfields) if (n > nfields)
growfldtab(n); growfldtab(n);