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:
parent
275a80ff33
commit
1debe1993f
2
run.c
2
run.c
@ -447,6 +447,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
|
|||||||
n = getrec(&record, &recsize, true);
|
n = getrec(&record, &recsize, true);
|
||||||
else { /* getline var */
|
else { /* getline var */
|
||||||
n = getrec(&buf, &bufsize, false);
|
n = getrec(&buf, &bufsize, false);
|
||||||
|
if (n > 0) {
|
||||||
x = execute(a[0]);
|
x = execute(a[0]);
|
||||||
setsval(x, buf);
|
setsval(x, buf);
|
||||||
if (is_number(x->sval, & result)) {
|
if (is_number(x->sval, & result)) {
|
||||||
@ -456,6 +457,7 @@ Cell *awkgetline(Node **a, int n) /* get next line from specific input */
|
|||||||
tempfree(x);
|
tempfree(x);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
setfval(r, (Awkfloat) n);
|
setfval(r, (Awkfloat) n);
|
||||||
free(buf);
|
free(buf);
|
||||||
return r;
|
return r;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user