diff options
author | Denys Vlasenko | 2018-12-23 00:13:15 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-12-23 00:13:15 +0100 |
commit | 9471bd46603d9f61c76d672b0a679c2b9446c3cf (patch) | |
tree | 1bde732177168db887f4c87b2f2ac663f67955ff /miscutils | |
parent | 01eb5e9da1546f5410831d3a5a8d268d630d2653 (diff) | |
download | busybox-9471bd46603d9f61c76d672b0a679c2b9446c3cf.zip busybox-9471bd46603d9f61c76d672b0a679c2b9446c3cf.tar.gz |
bc: fix empty lines in dc generating "bad token" message
function old new delta
zdc_program_asciify - 370 +370
zbc_program_pushArray - 147 +147
zbc_vm_process 824 828 +4
zbc_program_exec 4182 4046 -136
zdc_program_printStream 146 - -146
zbc_program_read 268 - -268
------------------------------------------------------------------------------
(add/remove: 2/2 grow/shrink: 1/1 up/down: 521/-550) Total: -29 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils')
-rw-r--r-- | miscutils/bc.c | 18 |
1 files changed, 10 insertions, 8 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 25150a9..a7b8aa4 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -6695,9 +6695,18 @@ static BC_STATUS zbc_vm_process(const char *text) // "print 1" part. IF_BC(s = zbc_parse_stmt_or_funcdef(&G.prs)); } else { + // Most of dc parsing assumes all whitespace, + // including '\n', is eaten. + while (G.prs.l.t.t == BC_LEX_NLINE) { + s = zbc_lex_next(&G.prs.l); + if (s) goto err; + if (G.prs.l.t.t == BC_LEX_EOF) + goto done; + } IF_DC(s = zdc_parse_expr(&G.prs)); } if (s || G_interrupt) { + err: bc_parse_reset(&G.prs); // includes bc_program_reset() RETURN_STATUS(BC_STATUS_FAILURE); } @@ -6735,13 +6744,6 @@ static BC_STATUS zbc_vm_process(const char *text) IF_BC(bc_vec_pop_all(&f->strs);) IF_BC(bc_vec_pop_all(&f->consts);) } else { - // Most of dc parsing assumes all whitespace, - // including '\n', is eaten. - if (G.prs.l.t.t == BC_LEX_NLINE) { - s = zbc_lex_next(&G.prs.l); - if (s) RETURN_STATUS(s); - } - if (G.prog.results.len == 0 && G.prog.vars.len == 0 ) { @@ -6762,7 +6764,7 @@ static BC_STATUS zbc_vm_process(const char *text) bc_vec_pop_all(&f->code); ip->inst_idx = 0; } - + done: dbg_lex_done("%s:%d done", __func__, __LINE__); RETURN_STATUS(s); } |