From 179536a5160006db2bd59772a96501f469bb6029 Mon Sep 17 00:00:00 2001 From: Cody Peter Mello Date: Tue, 25 Sep 2018 21:19:49 -0700 Subject: [PATCH] Print an error message for negative NF values --- bugs-fixed/README | 2 ++ bugs-fixed/negative-nf.awk | 1 + bugs-fixed/negative-nf.ok | 2 ++ lib.c | 2 ++ 4 files changed, 7 insertions(+) create mode 100644 bugs-fixed/negative-nf.awk create mode 100644 bugs-fixed/negative-nf.ok diff --git a/bugs-fixed/README b/bugs-fixed/README index 29c845f..dda3b2a 100644 --- a/bugs-fixed/README +++ b/bugs-fixed/README @@ -25,3 +25,5 @@ and also if CONVFMT changed. 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. negative-nf: Setting NF to a negative value caused a segmentation fault. diff --git a/bugs-fixed/negative-nf.awk b/bugs-fixed/negative-nf.awk new file mode 100644 index 0000000..6caeee4 --- /dev/null +++ b/bugs-fixed/negative-nf.awk @@ -0,0 +1 @@ +BEGIN { NF = -5; } diff --git a/bugs-fixed/negative-nf.ok b/bugs-fixed/negative-nf.ok new file mode 100644 index 0000000..71c8604 --- /dev/null +++ b/bugs-fixed/negative-nf.ok @@ -0,0 +1,2 @@ +./a.out: cannot set NF to a negative value + source line number 1 diff --git a/lib.c b/lib.c index ba6ebd4..8078db0 100644 --- a/lib.c +++ b/lib.c @@ -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 */ { + if (n < 0) + FATAL("cannot set NF to a negative value"); if (n > nfields) growfldtab(n);