aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 20:41:32 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-16 20:41:32 +0100
commit2e8be023cbd96c54256b5908837039100dc4fc45 (patch)
treef003d4c8f65613e0203354b76c0e4969c3bd83a4
parente6c40c48d96169ff27471c63c33e568e96fd5b82 (diff)
downloadbusybox-w32-2e8be023cbd96c54256b5908837039100dc4fc45.tar.gz
busybox-w32-2e8be023cbd96c54256b5908837039100dc4fc45.tar.bz2
busybox-w32-2e8be023cbd96c54256b5908837039100dc4fc45.zip
bc: allow only one <newline> between if() and stmt
Attempt to have more than one causes this error message: $ bc -q if (1)<cr> <cr> bc: no statement after 'if' Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c17
1 files changed, 13 insertions, 4 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 6e39aeed3..ed2497c4c 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3677,6 +3677,16 @@ static BC_STATUS zbc_parse_stmt(BcParse *p)
3677# define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS) 3677# define zbc_parse_stmt(...) (zbc_parse_stmt(__VA_ARGS__), BC_STATUS_SUCCESS)
3678#endif 3678#endif
3679 3679
3680static BC_STATUS zbc_parse_stmt_fail_if_bare_NLINE(BcParse *p, const char *after_X)
3681{
3682 if (p->l.t.t == BC_LEX_NLINE)
3683 RETURN_STATUS(bc_error_fmt("no statement after '%s'", after_X));
3684 RETURN_STATUS(zbc_parse_stmt(p));
3685}
3686#if ERRORS_ARE_FATAL
3687# define zbc_parse_stmt_fail_if_bare_NLINE((...) (zbc_parse_stmt_fail_if_bare_NLINE((__VA_ARGS__), BC_STATUS_SUCCESS)
3688#endif
3689
3680static void bc_parse_operator(BcParse *p, BcLexType type, size_t start, 3690static void bc_parse_operator(BcParse *p, BcLexType type, size_t start,
3681 size_t *nexprs) 3691 size_t *nexprs)
3682{ 3692{
@@ -4141,7 +4151,7 @@ static BC_STATUS zbc_parse_if(BcParse *p)
4141 bc_vec_push(&p->exits, &ip); 4151 bc_vec_push(&p->exits, &ip);
4142 bc_vec_push(&p->func->labels, &ip.idx); 4152 bc_vec_push(&p->func->labels, &ip.idx);
4143 4153
4144 s = zbc_parse_stmt(p); 4154 s = zbc_parse_stmt_fail_if_bare_NLINE(p, "if");
4145 if (s) RETURN_STATUS(s); 4155 if (s) RETURN_STATUS(s);
4146 4156
4147 dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t); 4157 dbg_lex("%s:%d in if after stmt: p->l.t.t:%d", __func__, __LINE__, p->l.t.t);
@@ -4220,8 +4230,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4220 bc_parse_push(p, BC_INST_JUMP_ZERO); 4230 bc_parse_push(p, BC_INST_JUMP_ZERO);
4221 bc_parse_pushIndex(p, ip.idx); 4231 bc_parse_pushIndex(p, ip.idx);
4222 4232
4223//TODO: diagnose "while(cond)<newline><newline>"? Now it is seen as "while() with empty body" 4233 s = zbc_parse_stmt_fail_if_bare_NLINE(p, "while");
4224 s = zbc_parse_stmt(p);
4225 if (s) RETURN_STATUS(s); 4234 if (s) RETURN_STATUS(s);
4226 4235
4227 n = *((size_t *) bc_vec_top(&p->conds)); 4236 n = *((size_t *) bc_vec_top(&p->conds));
@@ -4325,7 +4334,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4325 s = zbc_lex_next_and_skip_NLINE(&p->l); 4334 s = zbc_lex_next_and_skip_NLINE(&p->l);
4326 if (s) RETURN_STATUS(s); 4335 if (s) RETURN_STATUS(s);
4327 4336
4328 s = zbc_parse_stmt(p); 4337 s = zbc_parse_stmt_fail_if_bare_NLINE(p, "for");
4329 if (s) RETURN_STATUS(s); 4338 if (s) RETURN_STATUS(s);
4330 4339
4331 n = *((size_t *) bc_vec_top(&p->conds)); 4340 n = *((size_t *) bc_vec_top(&p->conds));