awkgetline: do not access unitialized data on EOF

getrec() returns 0 on EOF and leaves the contents of buf unchanged.
Fixes #133.
This commit is contained in:
Todd C. Miller 2021-11-01 11:58:54 -06:00
parent 275a80ff33
commit 1debe1993f

14
run.c
View File

@ -447,13 +447,15 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
n = getrec(&record, &recsize, true);
else { /* getline var */
n = getrec(&buf, &bufsize, false);
x = execute(a[0]);
setsval(x, buf);
if (is_number(x->sval, & result)) {
x->fval = result;
x->tval |= NUM;
if (n > 0) {
x = execute(a[0]);
setsval(x, buf);
if (is_number(x->sval, & result)) {
x->fval = result;
x->tval |= NUM;
}
tempfree(x);
}
tempfree(x);
}
}
setfval(r, (Awkfloat) n);