[git commit] bc: use unsigned division by 10 instead of signed

Denys Vlasenko vda.linux at googlemail.com
Wed Dec 5 18:05:32 UTC 2018


commit: https://git.busybox.net/busybox/commit/?id=b3cb90124bcf1786710c200c00530fd3f213929d
branch: https://git.busybox.net/busybox/commit/?id=refs/heads/master

function                                             old     new   delta
bc_num_k                                             990     988      -2

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 miscutils/bc.c | 7 ++++---
 1 file changed, 4 insertions(+), 3 deletions(-)

diff --git a/miscutils/bc.c b/miscutils/bc.c
index 07793e9d4..6dc79118a 100644
--- a/miscutils/bc.c
+++ b/miscutils/bc.c
@@ -1657,7 +1657,7 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b,
 	    a->len < BC_NUM_KARATSUBA_LEN || b->len < BC_NUM_KARATSUBA_LEN)
 	{
 		size_t i, j, len;
-		int carry;
+		unsigned carry;
 
 		bc_num_expand(c, a->len + b->len + 1);
 
@@ -1668,8 +1668,9 @@ static BcStatus bc_num_k(BcNum *restrict a, BcNum *restrict b,
 
 			carry = 0;
 			for (j = 0; j < a->len; ++j) {
-				int in = (int) c->num[i + j];
-				in += ((int) a->num[j]) * ((int) b->num[i]) + carry;
+				unsigned in = c->num[i + j];
+				in += ((unsigned) a->num[j]) * ((unsigned) b->num[i]) + carry;
+				// note: compilers prefer _unsigned_ div/const
 				carry = in / 10;
 				c->num[i + j] = (BcDig)(in % 10);
 			}


More information about the busybox-cvs mailing list