From 2212c1dc165fa4251ff5085eec768daf3a0f69e5 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Thu, 15 Nov 2018 05:10:40 +0000 Subject: bignum.c: ee should be signed In C, signed + unsigned of the same size results in unsigned (cf: ISO/IEC 9899:1990 section 6.2.1.5). However `num` is signed here. Which means the addition must be done in signed. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@65734 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 144970bba9..8dd70092cc 100644 --- a/bignum.c +++ b/bignum.c @@ -1511,15 +1511,16 @@ bigdivrem_mulsub(BDIGIT *zds, size_t zn, BDIGIT x, const BDIGIT *yds, size_t yn) i = 0; do { - BDIGIT_DBL ee; + BDIGIT_DBL_SIGNED ee; t2 += (BDIGIT_DBL)yds[i] * x; ee = num - BIGLO(t2); - num = (BDIGIT_DBL)zds[i] + ee; + num = (BDIGIT_DBL_SIGNED)zds[i] + ee; if (ee) zds[i] = BIGLO(num); num = BIGDN(num); t2 = BIGDN(t2); } while (++i < yn); - num += zds[i] - t2; /* borrow from high digit; don't update */ + num -= (BDIGIT_DBL_SIGNED)t2; + num += (BDIGIT_DBL_SIGNED)zds[yn]; /* borrow from high digit; don't update */ return num; } -- cgit v1.2.3