[git commit] dc: fix EOF handling in case of last line being incomplete
Denys Vlasenko
vda.linux at googlemail.com
Wed Dec 12 20:56:06 UTC 2018
commit: https://git.busybox.net/busybox/commit/?id=d8078a79beb665cb3c0408dbbbba132cff9fdc3b
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master
This wasn't working correctly:
$ echo -ne '10 20+p' | dc
30
Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
miscutils/bc.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
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)
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)
More information about the busybox-cvs
mailing list