ref: 7c33bdd2d31ade66cbf0ad4531fdbeda1d6cbba5
parent: 75ee3b3081edab418e443d499ec28ceda9121e93
author: cinap_lenrek <cinap_lenrek@felloff.net>
date: Tue Apr 16 12:13:30 EDT 2019
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
--- a/sys/src/cmd/awk/lib.c
+++ b/sys/src/cmd/awk/lib.c
@@ -155,10 +155,7 @@
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 @@
void nextfile(void)
{
- if (infile != &stdin)
+ if (infile != nil && infile != &stdin)
Bterm(infile);
infile = nil;
argno++;