aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-25 16:39:01 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-25 16:39:01 +0100
commitd4b721cc8b708a2fa4ddd821179c00865c11619e (patch)
tree6d78fc782b7ea047d46783f180d8f277a2b96839
parent73b3ebc0e18f95d9eda7e33dfc878f9792d1b1e1 (diff)
downloadbusybox-w32-d4b721cc8b708a2fa4ddd821179c00865c11619e.tar.gz
busybox-w32-d4b721cc8b708a2fa4ddd821179c00865c11619e.tar.bz2
busybox-w32-d4b721cc8b708a2fa4ddd821179c00865c11619e.zip
bc: shrink parsing code a bit more, disallow "auto a b c" (without commas)
function old new delta bc_parse_expr_empty_ok 1791 1785 -6 zbc_parse_stmt_possibly_auto 1675 1599 -76 ------------------------------------------------------------------------------ (add/remove: 0/0 grow/shrink: 0/2 up/down: 0/-82) Total: -82 bytes Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c46
1 files changed, 22 insertions, 24 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 2b370888c..ec2f86133 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3788,7 +3788,7 @@ static BC_STATUS zbc_parse_rightParen(BcParse *p, size_t ops_bgn, size_t *nexs)
3788 3788
3789 bc_vec_pop(&p->ops); 3789 bc_vec_pop(&p->ops);
3790 3790
3791 RETURN_STATUS(zbc_lex_next(&p->l)); 3791 RETURN_STATUS(BC_STATUS_SUCCESS);
3792} 3792}
3793#define zbc_parse_rightParen(...) (zbc_parse_rightParen(__VA_ARGS__) COMMA_SUCCESS) 3793#define zbc_parse_rightParen(...) (zbc_parse_rightParen(__VA_ARGS__) COMMA_SUCCESS)
3794 3794
@@ -4470,53 +4470,52 @@ static BC_STATUS zbc_parse_funcdef(BcParse *p)
4470static BC_STATUS zbc_parse_auto(BcParse *p) 4470static BC_STATUS zbc_parse_auto(BcParse *p)
4471{ 4471{
4472 BcStatus s; 4472 BcStatus s;
4473 bool comma, var, one;
4474 char *name; 4473 char *name;
4475 4474
4476 dbg_lex_enter("%s:%d entered", __func__, __LINE__); 4475 dbg_lex_enter("%s:%d entered", __func__, __LINE__);
4477 s = zbc_lex_next(&p->l); 4476 s = zbc_lex_next(&p->l);
4478 if (s) RETURN_STATUS(s); 4477 if (s) RETURN_STATUS(s);
4479 4478
4480 comma = false; 4479 for (;;) {
4481 one = p->l.lex == XC_LEX_NAME; 4480 bool var;
4481
4482 if (p->l.lex != XC_LEX_NAME)
4483 RETURN_STATUS(bc_error("bad 'auto' syntax"));
4482 4484
4483 while (p->l.lex == XC_LEX_NAME) {
4484 name = xstrdup(p->l.lex_buf.v); 4485 name = xstrdup(p->l.lex_buf.v);
4485 s = zbc_lex_next(&p->l); 4486 s = zbc_lex_next(&p->l);
4486 if (s) goto err; 4487 if (s) goto err;
4487 4488
4488 var = p->l.lex != BC_LEX_LBRACKET; 4489 var = (p->l.lex != BC_LEX_LBRACKET);
4489 if (!var) { 4490 if (!var) {
4490 s = zbc_lex_next(&p->l); 4491 s = zbc_lex_next(&p->l);
4491 if (s) goto err; 4492 if (s) goto err;
4492 4493
4493 if (p->l.lex != BC_LEX_RBRACKET) { 4494 if (p->l.lex != BC_LEX_RBRACKET) {
4494 s = bc_error("bad function definition"); 4495 s = bc_error("bad 'auto' syntax");
4495 goto err; 4496 goto err;
4496 } 4497 }
4497
4498 s = zbc_lex_next(&p->l);
4499 if (s) goto err;
4500 }
4501
4502 comma = p->l.lex == BC_LEX_COMMA;
4503 if (comma) {
4504 s = zbc_lex_next(&p->l); 4498 s = zbc_lex_next(&p->l);
4505 if (s) goto err; 4499 if (s) goto err;
4506 } 4500 }
4507 4501
4508 s = zbc_func_insert(p->func, name, var); 4502 s = zbc_func_insert(p->func, name, var);
4509 if (s) goto err; 4503 if (s) goto err;
4510 }
4511
4512 if (comma) RETURN_STATUS(bc_error("bad function definition"));
4513 if (!one) RETURN_STATUS(bc_error("no auto variable found"));
4514 4504
4515 if (p->l.lex != XC_LEX_NLINE && p->l.lex != BC_LEX_SCOLON) 4505 if (p->l.lex == XC_LEX_NLINE
4516 RETURN_STATUS(bc_error_bad_token()); 4506 || p->l.lex == BC_LEX_SCOLON
4507 //|| p->l.lex == BC_LEX_RBRACE // allow "define f() {auto a}"
4508 ) {
4509 break;
4510 }
4511 if (p->l.lex != BC_LEX_COMMA)
4512 RETURN_STATUS(bc_error("bad 'auto' syntax"));
4513 s = zbc_lex_next(&p->l); // skip comma
4514 if (s) RETURN_STATUS(s);
4515 }
4517 4516
4518 dbg_lex_done("%s:%d done", __func__, __LINE__); 4517 dbg_lex_done("%s:%d done", __func__, __LINE__);
4519 RETURN_STATUS(zbc_lex_next(&p->l)); 4518 RETURN_STATUS(BC_STATUS_SUCCESS);
4520 err: 4519 err:
4521 free(name); 4520 free(name);
4522 dbg_lex_done("%s:%d done (ERROR)", __func__, __LINE__); 4521 dbg_lex_done("%s:%d done (ERROR)", __func__, __LINE__);
@@ -4707,11 +4706,10 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
4707 && prev != XC_INST_SCALE && prev != XC_INST_IBASE 4706 && prev != XC_INST_SCALE && prev != XC_INST_IBASE
4708 && prev != XC_INST_OBASE && prev != BC_INST_LAST 4707 && prev != XC_INST_OBASE && prev != BC_INST_LAST
4709 ) { 4708 ) {
4710 s = bc_error("bad assignment:" 4709 return bc_error("bad assignment:"
4711 " left side must be variable" 4710 " left side must be variable"
4712 " or array element" 4711 " or array element"
4713 ); // note: shared string 4712 ); // note: shared string
4714 break;
4715 } 4713 }
4716 // Fallthrough. 4714 // Fallthrough.
4717 case XC_LEX_OP_POWER: 4715 case XC_LEX_OP_POWER:
@@ -4762,9 +4760,9 @@ static BcStatus bc_parse_expr_empty_ok(BcParse *p, uint8_t flags)
4762 } 4760 }
4763 s = zbc_parse_rightParen(p, ops_bgn, &nexprs); 4761 s = zbc_parse_rightParen(p, ops_bgn, &nexprs);
4764 nparens--; 4762 nparens--;
4763 get_token = true;
4765 paren_expr = rprn = true; 4764 paren_expr = rprn = true;
4766 bin_last = false; 4765 bin_last = false;
4767 //get_token = false; - already is
4768 break; 4766 break;
4769 case XC_LEX_NAME: 4767 case XC_LEX_NAME:
4770 if (BC_PARSE_LEAF(prev, rprn)) 4768 if (BC_PARSE_LEAF(prev, rprn))