diff options
author | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 00:29:24 +0100 |
---|---|---|
committer | Denys Vlasenko <vda.linux@googlemail.com> | 2018-12-12 00:29:24 +0100 |
commit | 69171dc466ab94daf14e7560efe92c5050b0c1b1 (patch) | |
tree | 4b84059ed715a3fd02ab51afbfb2d6c1270b9628 | |
parent | 12b9eaf787146d8706a343d87f19902e6892be86 (diff) | |
download | busybox-w32-69171dc466ab94daf14e7560efe92c5050b0c1b1.tar.gz busybox-w32-69171dc466ab94daf14e7560efe92c5050b0c1b1.tar.bz2 busybox-w32-69171dc466ab94daf14e7560efe92c5050b0c1b1.zip |
bc: simplify nested read() check
function old new delta
bc_vm_run 622 624 +2
dc_main 186 187 +1
bc_main 72 73 +1
bc_program_read 312 277 -35
------------------------------------------------------------------------------
(add/remove: 0/0 grow/shrink: 3/1 up/down: 4/-35) Total: -31 bytes
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r-- | miscutils/bc.c | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 70db2ce3d..791275c8c 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c | |||
@@ -736,6 +736,7 @@ typedef struct BcProgram { | |||
736 | struct globals { | 736 | struct globals { |
737 | IF_FEATURE_BC_SIGNALS(smallint ttyin;) | 737 | IF_FEATURE_BC_SIGNALS(smallint ttyin;) |
738 | IF_FEATURE_CLEAN_UP(smallint exiting;) | 738 | IF_FEATURE_CLEAN_UP(smallint exiting;) |
739 | smallint in_read; | ||
739 | char sbgn; | 740 | char sbgn; |
740 | char send; | 741 | char send; |
741 | 742 | ||
@@ -5390,20 +5391,18 @@ static BcStatus bc_program_read(void) | |||
5390 | BcParse parse; | 5391 | BcParse parse; |
5391 | BcVec buf; | 5392 | BcVec buf; |
5392 | BcInstPtr ip; | 5393 | BcInstPtr ip; |
5393 | size_t i; | 5394 | BcFunc *f; |
5394 | BcFunc *f = bc_program_func(BC_PROG_READ); | ||
5395 | 5395 | ||
5396 | for (i = 0; i < G.prog.stack.len; ++i) { | 5396 | if (G.in_read) |
5397 | BcInstPtr *ip_ptr = bc_vec_item(&G.prog.stack, i); | 5397 | return bc_error_nested_read_call(); |
5398 | if (ip_ptr->func == BC_PROG_READ) | ||
5399 | return bc_error_nested_read_call(); | ||
5400 | } | ||
5401 | 5398 | ||
5399 | f = bc_program_func(BC_PROG_READ); | ||
5402 | bc_vec_pop_all(&f->code); | 5400 | bc_vec_pop_all(&f->code); |
5403 | bc_char_vec_init(&buf); | 5401 | bc_char_vec_init(&buf); |
5404 | 5402 | ||
5405 | sv_file = G.prog.file; | 5403 | sv_file = G.prog.file; |
5406 | G.prog.file = NULL; | 5404 | G.prog.file = NULL; |
5405 | G.in_read = 1; | ||
5407 | 5406 | ||
5408 | s = bc_read_line(&buf); | 5407 | s = bc_read_line(&buf); |
5409 | //if (s) goto io_err; - wrong, nonzero return means EOF, not error | 5408 | //if (s) goto io_err; - wrong, nonzero return means EOF, not error |
@@ -5434,6 +5433,7 @@ static BcStatus bc_program_read(void) | |||
5434 | exec_err: | 5433 | exec_err: |
5435 | bc_parse_free(&parse); | 5434 | bc_parse_free(&parse); |
5436 | //io_err: | 5435 | //io_err: |
5436 | G.in_read = 0; | ||
5437 | G.prog.file = sv_file; | 5437 | G.prog.file = sv_file; |
5438 | bc_vec_free(&buf); | 5438 | bc_vec_free(&buf); |
5439 | return s; | 5439 | return s; |