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
This commit is contained in:
cinap_lenrek 2019-04-16 16:13:30 +02:00
parent 75ee3b3081
commit 7c33bdd2d3

View file

@ -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++;