summaryrefslogtreecommitdiff
path: root/miscutils/bc.c
diff options
context:
space:
mode:
authorDenys Vlasenko2018-12-12 21:56:06 +0100
committerDenys Vlasenko2018-12-12 21:56:06 +0100
commitd8078a79beb665cb3c0408dbbbba132cff9fdc3b (patch)
treefb5d395bbbf0382d80d30f09d5e67d4a2ea5abe8 /miscutils/bc.c
parent9a23b07c4c0d06c40d7c0ce91c5fdf7c8449ac49 (diff)
downloadbusybox-d8078a79beb665cb3c0408dbbbba132cff9fdc3b.zip
busybox-d8078a79beb665cb3c0408dbbbba132cff9fdc3b.tar.gz
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>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r--miscutils/bc.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 3d26c39..9cc29f0 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -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)