aboutsummaryrefslogtreecommitdiff
path: root/miscutils
diff options
context:
space:
mode:
Diffstat (limited to 'miscutils')
-rw-r--r--miscutils/bc.c17
1 files changed, 10 insertions, 7 deletions
diff --git a/miscutils/bc.c b/miscutils/bc.c
index 2e3c4139e..71b419d8f 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1399,12 +1399,16 @@ static void bc_num_ten(BcNum *n)
1399 n->num[1] = 1; 1399 n->num[1] = 1;
1400} 1400}
1401 1401
1402// Note: this also sets BcNum to zero
1402static void bc_num_init(BcNum *n, size_t req) 1403static void bc_num_init(BcNum *n, size_t req)
1403{ 1404{
1404 req = req >= BC_NUM_DEF_SIZE ? req : BC_NUM_DEF_SIZE; 1405 req = req >= BC_NUM_DEF_SIZE ? req : BC_NUM_DEF_SIZE;
1405 memset(n, 0, sizeof(BcNum)); 1406 //memset(n, 0, sizeof(BcNum)); - cleared by assignments below
1406 n->num = xmalloc(req); 1407 n->num = xmalloc(req);
1407 n->cap = req; 1408 n->cap = req;
1409 n->rdx = 0;
1410 n->len = 0;
1411 n->neg = false;
1408} 1412}
1409 1413
1410static void bc_num_init_DEF_SIZE(BcNum *n) 1414static void bc_num_init_DEF_SIZE(BcNum *n)
@@ -2288,7 +2292,7 @@ static void bc_num_parseBase(BcNum *n, const char *val, BcNum *base)
2288 } 2292 }
2289 2293
2290 bc_num_init(&result, base->len); 2294 bc_num_init(&result, base->len);
2291 bc_num_zero(&result); 2295 //bc_num_zero(&result); - already is
2292 bc_num_one(&mult); 2296 bc_num_one(&mult);
2293 2297
2294 for (i += 1, digits = 0; i < len; ++i, ++digits) { 2298 for (i += 1, digits = 0; i < len; ++i, ++digits) {
@@ -6209,7 +6213,7 @@ static BcStatus bc_program_return(char inst)
6209 } 6213 }
6210 else { 6214 else {
6211 bc_num_init_DEF_SIZE(&res.d.n); 6215 bc_num_init_DEF_SIZE(&res.d.n);
6212 bc_num_zero(&res.d.n); 6216 //bc_num_zero(&res.d.n); - already is
6213 } 6217 }
6214 6218
6215 // We need to pop arguments as well, so this takes that into account. 6219 // We need to pop arguments as well, so this takes that into account.
@@ -6768,8 +6772,7 @@ static BcStatus bc_program_exec(void)
6768 bc_num_init_DEF_SIZE(&r.d.n); 6772 bc_num_init_DEF_SIZE(&r.d.n);
6769 if (!bc_num_cmp(num, &G.prog.zero)) 6773 if (!bc_num_cmp(num, &G.prog.zero))
6770 bc_num_one(&r.d.n); 6774 bc_num_one(&r.d.n);
6771 else 6775 //else bc_num_zero(&r.d.n); - already is
6772 bc_num_zero(&r.d.n);
6773 bc_program_retire(&r, BC_RESULT_TEMP); 6776 bc_program_retire(&r, BC_RESULT_TEMP);
6774 break; 6777 break;
6775 case BC_INST_NEG: 6778 case BC_INST_NEG:
@@ -7379,10 +7382,10 @@ static void bc_program_init(void)
7379#endif 7382#endif
7380 7383
7381 bc_num_init_DEF_SIZE(&G.prog.last); 7384 bc_num_init_DEF_SIZE(&G.prog.last);
7382 bc_num_zero(&G.prog.last); 7385 //bc_num_zero(&G.prog.last); - already is
7383 7386
7384 bc_num_init_DEF_SIZE(&G.prog.zero); 7387 bc_num_init_DEF_SIZE(&G.prog.zero);
7385 bc_num_zero(&G.prog.zero); 7388 //bc_num_zero(&G.prog.zero); - already is
7386 7389
7387 bc_num_init_DEF_SIZE(&G.prog.one); 7390 bc_num_init_DEF_SIZE(&G.prog.one);
7388 bc_num_one(&G.prog.one); 7391 bc_num_one(&G.prog.one);