From 7c33bdd2d31ade66cbf0ad4531fdbeda1d6cbba5 Mon Sep 17 00:00:00 2001 From: cinap_lenrek Date: Tue, 16 Apr 2019 16:13:30 +0200 Subject: awk: fix nextfile crash (thanks leetspete) to reproduce the bug: term% awk 'BEGIN{nextfile; nextfile;}' sys: trap: fault read addr=0x10 pc=0x00019a3a awk 6584: suicide: sys: trap: fault read addr=0x10 pc=0x00019a3a --- sys/src/cmd/awk/lib.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) (limited to 'sys/src/cmd/awk/lib.c') diff --git a/sys/src/cmd/awk/lib.c b/sys/src/cmd/awk/lib.c index d32bbf350..076fb79d1 100644 --- a/sys/src/cmd/awk/lib.c +++ b/sys/src/cmd/awk/lib.c @@ -155,10 +155,7 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ return 1; } /* Beof arrived on this file; set up next */ - if (infile != &stdin) - Bterm(infile); - infile = nil; - argno++; + nextfile(); } *pbuf = buf; *pbufsize = bufsize; @@ -167,7 +164,7 @@ int getrec(char **pbuf, int *pbufsize, int isrecord) /* get next input record */ void nextfile(void) { - if (infile != &stdin) + if (infile != nil && infile != &stdin) Bterm(infile); infile = nil; argno++; -- cgit v1.2.3