aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 21:08:30 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 21:08:30 +0100
commit5d18f6be90a940f80c3b7238dc7a8b42a41f55bd (patch)
tree9e1bb7f45a3ba0aa834d4a27e62cf5ab0a3d55ff
parentcb18b546f7ee9d1c9315c7357ab620e55f0fa8f3 (diff)
downloadbusybox-w32-5d18f6be90a940f80c3b7238dc7a8b42a41f55bd.tar.gz
busybox-w32-5d18f6be90a940f80c3b7238dc7a8b42a41f55bd.tar.bz2
busybox-w32-5d18f6be90a940f80c3b7238dc7a8b42a41f55bd.zip
bc: fix "print 1,2,3" parsing
function old new delta zbc_parse_stmt_possibly_auto 2245 2180 -65 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/1 up/down: 0/-65) Total: -65 bytes text data bss dec hex filename 982237 485 7296 990018 f1b42 busybox_old 982152 485 7296 989933 f1aed busybox_unstripped Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c31
-rwxr-xr-xtestsuite/bc.tests5
2 files changed, 13 insertions, 23 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 2dc64dbc6..9f40a551e 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -4048,38 +4048,23 @@ static BC_STATUS zbc_parse_print(BcParse *p)
4048{ 4048{
4049 BcStatus s; 4049 BcStatus s;
4050 BcLexType type; 4050 BcLexType type;
4051 bool comma;
4052 4051
4053 s = zbc_lex_next(&p->l); 4052 for (;;) {
4054 if (s) RETURN_STATUS(s); 4053 s = zbc_lex_next(&p->l);
4055 4054 if (s) RETURN_STATUS(s);
4056 type = p->l.t.t; 4055 type = p->l.t.t;
4057
4058 if (type == BC_LEX_SCOLON || type == BC_LEX_NLINE)
4059 RETURN_STATUS(bc_error("bad print statement"));
4060
4061 comma = false;
4062 while (type != BC_LEX_SCOLON && type != BC_LEX_NLINE) {
4063 if (type == BC_LEX_STR) { 4056 if (type == BC_LEX_STR) {
4064 s = zbc_parse_string(p, BC_INST_PRINT_POP); 4057 s = zbc_parse_string(p, BC_INST_PRINT_POP);
4065 if (s) RETURN_STATUS(s);
4066 } else { 4058 } else {
4067 s = zbc_parse_expr(p, 0, bc_parse_next_print); 4059 s = zbc_parse_expr(p, 0, bc_parse_next_print);
4068 if (s) RETURN_STATUS(s);
4069 bc_parse_push(p, BC_INST_PRINT_POP); 4060 bc_parse_push(p, BC_INST_PRINT_POP);
4070 } 4061 }
4071 4062 if (s) RETURN_STATUS(s);
4072 comma = p->l.t.t == BC_LEX_COMMA; 4063 if (p->l.t.t != BC_LEX_COMMA)
4073 if (comma) { 4064 break;
4074 s = zbc_lex_next(&p->l);
4075 if (s) RETURN_STATUS(s);
4076 }
4077 type = p->l.t.t;
4078 } 4065 }
4079 4066
4080 if (comma) RETURN_STATUS(bc_error_bad_token()); 4067 RETURN_STATUS(s);
4081
4082 RETURN_STATUS(zbc_lex_next(&p->l));
4083} 4068}
4084#if ERRORS_ARE_FATAL 4069#if ERRORS_ARE_FATAL
4085# define zbc_parse_print(...) (zbc_parse_print(__VA_ARGS__), BC_STATUS_SUCCESS) 4070# define zbc_parse_print(...) (zbc_parse_print(__VA_ARGS__), BC_STATUS_SUCCESS)
diff --git a/testsuite/bc.tests b/testsuite/bc.tests
index 36baeea89..21b26008f 100755
--- a/testsuite/bc.tests
+++ b/testsuite/bc.tests
@@ -71,6 +71,11 @@ testing "bc while(cond)<NL>" \
71 "8\n7\n6\n5\n4\n3\n2\n1\n9\n" \ 71 "8\n7\n6\n5\n4\n3\n2\n1\n9\n" \
72 "" "i=9;while(--i)\ni\n9" 72 "" "i=9;while(--i)\ni\n9"
73 73
74testing "bc print 1,2,3" \
75 "bc" \
76 "123" \
77 "" "print 1,2,3"
78
74tar xJf bc_large.tar.xz 79tar xJf bc_large.tar.xz
75 80
76for f in bc*.bc; do 81for f in bc*.bc; do