diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 21:56:06 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 21:56:06 +0100 |
commit | d8078a79beb665cb3c0408dbbbba132cff9fdc3b (patch) | |
tree | fb5d395bbbf0382d80d30f09d5e67d4a2ea5abe8 | |
parent | 9a23b07c4c0d06c40d7c0ce91c5fdf7c8449ac49 (diff) | |
download | busybox-w32-d8078a79beb665cb3c0408dbbbba132cff9fdc3b.tar.gz busybox-w32-d8078a79beb665cb3c0408dbbbba132cff9fdc3b.tar.bz2 busybox-w32-d8078a79beb665cb3c0408dbbbba132cff9fdc3b.zip |
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>
-rw-r--r-- | miscutils/bc.c | 4 |
1 files changed, 3 insertions, 1 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 3d26c39a7..9cc29f0ea 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -1425,7 +1425,9 @@ static BcStatus bc_read_line(BcVec *vec) | |||
1425 | if (c == EOF) { | 1425 | if (c == EOF) { |
1426 | if (ferror(stdin)) | 1426 | if (ferror(stdin)) |
1427 | quit(); // this emits error message | 1427 | quit(); // this emits error message |
1428 | s = BC_STATUS_EOF; | 1428 | // If we had some input before EOF, do not report EOF yet: |
1429 | if (vec->len == 0) | ||
1430 | s = BC_STATUS_EOF; | ||
1429 | // Note: EOF does not append '\n', therefore: | 1431 | // Note: EOF does not append '\n', therefore: |
1430 | // printf 'print 123\n' | bc - works | 1432 | // printf 'print 123\n' | bc - works |
1431 | // printf 'print 123' | bc - fails (syntax error) | 1433 | // printf 'print 123' | bc - fails (syntax error) |