dc: fix EOF handling in case of last line being incomplete

This wasn't working correctly:

$ echo -ne '10 20+p' | dc
30

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2018-12-12 21:56:06 +01:00
parent 9a23b07c4c
commit d8078a79be

View File

@ -1425,7 +1425,9 @@ static BcStatus bc_read_line(BcVec *vec)
if (c == EOF) {
if (ferror(stdin))
quit(); // this emits error message
s = BC_STATUS_EOF;
// If we had some input before EOF, do not report EOF yet:
if (vec->len == 0)
s = BC_STATUS_EOF;
// Note: EOF does not append '\n', therefore:
// printf 'print 123\n' | bc - works
// printf 'print 123' | bc - fails (syntax error)