aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--miscutils/bc.c13
-rwxr-xr-xtestsuite/bc.tests17
2 files changed, 22 insertions, 8 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index ca14c1ba7..979d5113d 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -3642,7 +3642,7 @@ static void bc_parse_create(BcParse *p, size_t func)
3642 memset(p, 0, sizeof(BcParse)); 3642 memset(p, 0, sizeof(BcParse));
3643 3643
3644 bc_lex_init(&p->l); 3644 bc_lex_init(&p->l);
3645 bc_vec_init(&p->exits, sizeof(BcInstPtr), NULL); 3645 bc_vec_init(&p->exits, sizeof(size_t), NULL);
3646 bc_vec_init(&p->conds, sizeof(size_t), NULL); 3646 bc_vec_init(&p->conds, sizeof(size_t), NULL);
3647 bc_vec_init(&p->ops, sizeof(BcLexType), NULL); 3647 bc_vec_init(&p->ops, sizeof(BcLexType), NULL);
3648 3648
@@ -4192,7 +4192,7 @@ static BC_STATUS zbc_parse_while(BcParse *p)
4192 ip.func = 1; 4192 ip.func = 1;
4193 ip.len = 0; 4193 ip.len = 0;
4194 4194
4195 bc_vec_push(&p->exits, &ip); 4195 bc_vec_push(&p->exits, &ip.idx);
4196 bc_vec_push(&p->func->labels, &ip.idx); 4196 bc_vec_push(&p->func->labels, &ip.idx);
4197 4197
4198 s = zbc_parse_expr(p, BC_PARSE_REL, bc_parse_next_rel); 4198 s = zbc_parse_expr(p, BC_PARSE_REL, bc_parse_next_rel);
@@ -4294,7 +4294,7 @@ static BC_STATUS zbc_parse_for(BcParse *p)
4294 ip.func = 1; 4294 ip.func = 1;
4295 ip.len = 0; 4295 ip.len = 0;
4296 4296
4297 bc_vec_push(&p->exits, &ip); 4297 bc_vec_push(&p->exits, &ip.idx);
4298 bc_vec_push(&p->func->labels, &ip.idx); 4298 bc_vec_push(&p->func->labels, &ip.idx);
4299 4299
4300 // for(...)<newline>stmt is accepted as well 4300 // for(...)<newline>stmt is accepted as well
@@ -4328,14 +4328,11 @@ static BC_STATUS zbc_parse_break_or_continue(BcParse *p, BcLexType type)
4328 size_t i; 4328 size_t i;
4329 4329
4330 if (type == BC_LEX_KEY_BREAK) { 4330 if (type == BC_LEX_KEY_BREAK) {
4331 BcInstPtr *ipp;
4332
4333 if (p->exits.len == 0) // none of the enclosing blocks is a loop 4331 if (p->exits.len == 0) // none of the enclosing blocks is a loop
4334 RETURN_STATUS(bc_error_bad_token()); 4332 RETURN_STATUS(bc_error_bad_token());
4335 ipp = bc_vec_top(&p->exits); 4333 i = *(size_t*)bc_vec_top(&p->exits);
4336 i = ipp->idx;
4337 } else { 4334 } else {
4338 i = *((size_t *) bc_vec_top(&p->conds)); 4335 i = *(size_t*)bc_vec_top(&p->conds);
4339 } 4336 }
4340 4337
4341 bc_parse_push(p, BC_INST_JUMP); 4338 bc_parse_push(p, BC_INST_JUMP);
diff --git a/testsuite/bc.tests b/testsuite/bc.tests
index 0690e9c6f..d057bea17 100755
--- a/testsuite/bc.tests
+++ b/testsuite/bc.tests
@@ -134,6 +134,23 @@ while(i--) {
13499 13499
135" 135"
136 136
137testing "bc continue in for" \
138 "bc" \
139 "\
1401
14177
1422
14399
144" \
145 "" "\
146for(i=1; i<3; i++) {
147 i
148 if(i==2) continue
149 77
150}
15199
152"
153
137tar xJf bc_large.tar.xz 154tar xJf bc_large.tar.xz
138 155
139for f in bc*.bc; do 156for f in bc*.bc; do