diff options
author | Denys Vlasenko | 2018-12-10 12:33:40 +0100 |
---|---|---|
committer | Denys Vlasenko | 2018-12-10 12:33:40 +0100 |
commit | 44d79d866dc4c9bb0c3bba47612feae78365a046 (patch) | |
tree | fff8e644c1274455187b2ee8c99969db26525baf /miscutils/bc.c | |
parent | b696d9ec2044a1fd7906c1b2a2a747aff7c3f79f (diff) | |
download | busybox-44d79d866dc4c9bb0c3bba47612feae78365a046.zip busybox-44d79d866dc4c9bb0c3bba47612feae78365a046.tar.gz |
bc: simplify bc_program_print()
function old new delta
bc_program_print 730 713 -17
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'miscutils/bc.c')
-rw-r--r-- | miscutils/bc.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c index 33abe93..1879581 100644 --- a/miscutils/bc.c +++ b/miscutils/bc.c @@ -5737,15 +5737,14 @@ static BcStatus bc_program_print(char inst, size_t idx) { BcStatus s = BC_STATUS_SUCCESS; BcResult *r; - size_t len, i; - char *str; - BcNum *num = NULL; + BcNum *num; bool pop = inst != BC_INST_PRINT; if (!BC_PROG_STACK(&G.prog.results, idx + 1)) return bc_error_stack_has_too_few_elements(); r = bc_vec_item_rev(&G.prog.results, idx); + num = NULL; // is this NULL necessary? s = bc_program_num(r, &num, false); if (s) return s; @@ -5754,16 +5753,18 @@ static BcStatus bc_program_print(char inst, size_t idx) if (!s) bc_num_copy(&G.prog.last, num); } else { + char *str; idx = (r->t == BC_RESULT_STR) ? r->d.id.idx : num->rdx; str = *bc_program_str(idx); if (inst == BC_INST_PRINT_STR) { - for (i = 0, len = strlen(str); i < len; ++i) { - char c = str[i]; + for (;;) { + char c = *str++; + if (c == '\0') break; bb_putchar(c); - if (c == '\n') G.prog.nchars = SIZE_MAX; ++G.prog.nchars; + if (c == '\n') G.prog.nchars = 0; } } else { |