aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2018-12-18 12:55:40 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2018-12-18 12:55:40 +0100
commit6b0fbd14fc0566a4f6cedf50f6301143e74adca5 (patch)
tree8812e9e0dec24e4486268715083cff91394ee669
parent71c82d1d8ca0617290600050728feda906878115 (diff)
downloadbusybox-w32-6b0fbd14fc0566a4f6cedf50f6301143e74adca5.tar.gz
busybox-w32-6b0fbd14fc0566a4f6cedf50f6301143e74adca5.tar.bz2
busybox-w32-6b0fbd14fc0566a4f6cedf50f6301143e74adca5.zip
bc: rewrite more for() loops
function old new delta bc_program_name 75 67 -8 Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--miscutils/bc.c28
1 files changed, 16 insertions, 12 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 0cd8ba6b4..927873d86 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -2064,7 +2064,7 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size
2064 BcNum copy; 2064 BcNum copy;
2065 unsigned long pow; 2065 unsigned long pow;
2066 size_t i, powrdx, resrdx; 2066 size_t i, powrdx, resrdx;
2067 bool neg, zero; 2067 bool neg;
2068 2068
2069 if (b->rdx) RETURN_STATUS(bc_error("non integer number")); 2069 if (b->rdx) RETURN_STATUS(bc_error("non integer number"));
2070 2070
@@ -2116,7 +2116,6 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size
2116 bc_num_copy(c, &copy); 2116 bc_num_copy(c, &copy);
2117 2117
2118 for (resrdx = powrdx, pow >>= 1; pow != 0; pow >>= 1) { 2118 for (resrdx = powrdx, pow >>= 1; pow != 0; pow >>= 1) {
2119
2120 powrdx <<= 1; 2119 powrdx <<= 1;
2121 s = zbc_num_mul(&copy, &copy, &copy, powrdx); 2120 s = zbc_num_mul(&copy, &copy, &copy, powrdx);
2122 if (s) goto err; 2121 if (s) goto err;
@@ -2141,10 +2140,13 @@ static FAST_FUNC BC_STATUS zbc_num_p(BcNum *a, BcNum *b, BcNum *restrict c, size
2141 if (c->rdx > scale) bc_num_truncate(c, c->rdx - scale); 2140 if (c->rdx > scale) bc_num_truncate(c, c->rdx - scale);
2142 2141
2143 // We can't use bc_num_clean() here. 2142 // We can't use bc_num_clean() here.
2144 for (zero = true, i = 0; zero && i < c->len; ++i) zero = !c->num[i]; 2143 for (i = 0; i < c->len; ++i)
2145 if (zero) bc_num_setToZero(c, scale); 2144 if (c->num[i] != 0)
2145 goto skip;
2146 bc_num_setToZero(c, scale);
2147 skip:
2146 2148
2147err: 2149 err:
2148 bc_num_free(&copy); 2150 bc_num_free(&copy);
2149 RETURN_STATUS(s); 2151 RETURN_STATUS(s);
2150} 2152}
@@ -2989,7 +2991,7 @@ static BC_STATUS zbc_lex_string(BcLex *l)
2989 2991
2990 l->t.t = BC_LEX_STR; 2992 l->t.t = BC_LEX_STR;
2991 2993
2992 for (c = l->buf[i]; c != 0 && c != '"'; c = l->buf[++i]) 2994 for (c = l->buf[i]; c != '\0' && c != '"'; c = l->buf[++i])
2993 nls += (c == '\n'); 2995 nls += (c == '\n');
2994 2996
2995 if (c == '\0') { 2997 if (c == '\0') {
@@ -5246,14 +5248,16 @@ static size_t bc_program_index(char *code, size_t *bgn)
5246static char *bc_program_name(char *code, size_t *bgn) 5248static char *bc_program_name(char *code, size_t *bgn)
5247{ 5249{
5248 size_t i; 5250 size_t i;
5249 char c, *s, *str = code + *bgn, *ptr = strchr(str, BC_PARSE_STREND); 5251 char *s, *str = code + *bgn, *ptr = strchr(str, BC_PARSE_STREND);
5250 5252
5251 s = xmalloc(ptr - str + 1); 5253 s = xmalloc(ptr - str + 1);
5252 c = code[(*bgn)++]; 5254 i = 0;
5253 5255 for (;;) {
5254 for (i = 0; c != 0 && c != BC_PARSE_STREND; c = code[(*bgn)++], ++i) 5256 char c = code[(*bgn)++];
5255 s[i] = c; 5257 if (c == '\0' || c == BC_PARSE_STREND)
5256 5258 break;
5259 s[i++] = c;
5260 }
5257 s[i] = '\0'; 5261 s[i] = '\0';
5258 5262
5259 return s; 5263 return s;