awk: next_input_file can return NULL, don't SEGV in this case.
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
parent
e8f36330d9
commit
f65c5f5c54
@ -2627,7 +2627,7 @@ static var *evaluate(node *op, var *res)
|
|||||||
rsm = iF;
|
rsm = iF;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!rsm->F) {
|
if (!rsm || !rsm->F) {
|
||||||
setvar_i(intvar[ERRNO], errno);
|
setvar_i(intvar[ERRNO], errno);
|
||||||
setvar_i(res, -1);
|
setvar_i(res, -1);
|
||||||
break;
|
break;
|
||||||
@ -2961,7 +2961,7 @@ static rstream *next_input_file(void)
|
|||||||
#define rsm (G.next_input_file__rsm)
|
#define rsm (G.next_input_file__rsm)
|
||||||
#define files_happen (G.next_input_file__files_happen)
|
#define files_happen (G.next_input_file__files_happen)
|
||||||
|
|
||||||
FILE *F = NULL;
|
FILE *F;
|
||||||
const char *fname, *ind;
|
const char *fname, *ind;
|
||||||
|
|
||||||
if (rsm.F)
|
if (rsm.F)
|
||||||
@ -2969,19 +2969,21 @@ static rstream *next_input_file(void)
|
|||||||
rsm.F = NULL;
|
rsm.F = NULL;
|
||||||
rsm.pos = rsm.adv = 0;
|
rsm.pos = rsm.adv = 0;
|
||||||
|
|
||||||
do {
|
for (;;) {
|
||||||
if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) {
|
if (getvar_i(intvar[ARGIND])+1 >= getvar_i(intvar[ARGC])) {
|
||||||
if (files_happen)
|
if (files_happen)
|
||||||
return NULL;
|
return NULL;
|
||||||
fname = "-";
|
fname = "-";
|
||||||
F = stdin;
|
F = stdin;
|
||||||
} else {
|
break;
|
||||||
|
}
|
||||||
ind = getvar_s(incvar(intvar[ARGIND]));
|
ind = getvar_s(incvar(intvar[ARGIND]));
|
||||||
fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind));
|
fname = getvar_s(findvar(iamarray(intvar[ARGV]), ind));
|
||||||
if (fname && *fname && !is_assignment(fname))
|
if (fname && *fname && !is_assignment(fname)) {
|
||||||
F = xfopen_stdin(fname);
|
F = xfopen_stdin(fname);
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
} while (!F);
|
|
||||||
|
|
||||||
files_happen = TRUE;
|
files_happen = TRUE;
|
||||||
setvar_s(intvar[FILENAME], fname);
|
setvar_s(intvar[FILENAME], fname);
|
||||||
|
Loading…
Reference in New Issue
Block a user