aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-12 00:29:24 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-12 00:29:24 +0100
commit69171dc466ab94daf14e7560efe92c5050b0c1b1 (patch)
tree4b84059ed715a3fd02ab51afbfb2d6c1270b9628
parent12b9eaf787146d8706a343d87f19902e6892be86 (diff)
downloadbusybox-69171dc466ab94daf14e7560efe92c5050b0c1b1.tar.gz
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.c14
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 {
struct globals {
IF_FEATURE_BC_SIGNALS(smallint ttyin;)
IF_FEATURE_CLEAN_UP(smallint exiting;)
+ smallint in_read;
char sbgn;
char send;
@@ -5390,20 +5391,18 @@ static BcStatus bc_program_read(void)
BcParse parse;
BcVec buf;
BcInstPtr ip;
- size_t i;
- BcFunc *f = bc_program_func(BC_PROG_READ);
+ BcFunc *f;
- for (i = 0; i < G.prog.stack.len; ++i) {
- BcInstPtr *ip_ptr = bc_vec_item(&G.prog.stack, i);
- if (ip_ptr->func == BC_PROG_READ)
- return bc_error_nested_read_call();
- }
+ if (G.in_read)
+ return bc_error_nested_read_call();
+ f = bc_program_func(BC_PROG_READ);
bc_vec_pop_all(&f->code);
bc_char_vec_init(&buf);
sv_file = G.prog.file;
G.prog.file = NULL;
+ G.in_read = 1;
s = bc_read_line(&buf);
//if (s) goto io_err; - wrong, nonzero return means EOF, not error
@@ -5434,6 +5433,7 @@ static BcStatus bc_program_read(void)
exec_err:
bc_parse_free(&parse);
//io_err:
+ G.in_read = 0;
G.prog.file = sv_file;
bc_vec_free(&buf);
return s;