summaryrefslogtreecommitdiff
path: root/sys/src/cmd/awk
diff options
context:
space:
mode:
authorcinap_lenrek <cinap_lenrek@felloff.net>2019-04-16 16:13:30 +0200
committercinap_lenrek <cinap_lenrek@felloff.net>2019-04-16 16:13:30 +0200
commit7c33bdd2d31ade66cbf0ad4531fdbeda1d6cbba5 (patch)
tree07dac68eb191f26c15f2b04d095e24861d021f14 /sys/src/cmd/awk
parent75ee3b3081edab418e443d499ec28ceda9121e93 (diff)
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
Diffstat (limited to 'sys/src/cmd/awk')
-rw-r--r--sys/src/cmd/awk/lib.c7
1 files changed, 2 insertions, 5 deletions
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++;