diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-10 03:34:38 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2013-04-10 03:34:38 +0000 |
commit | fa9b5bf223c6dc81ae3f128bfb02a7f69cb7f3b6 (patch) | |
tree | b72f79f9cfe53eaf963bbbeef53330822c3e14d7 /bignum.c | |
parent | ea16ec561fb022a204b876be4e3dfb0e08afac58 (diff) | |
download | ruby-fa9b5bf223c6dc81ae3f128bfb02a7f69cb7f3b6.tar.gz |
* bignum.c (rb_ll2big): Don't overflow on signed integer negation.
* ext/bigdecimal/bigdecimal.c (MUL_OVERFLOW_SIGNED_VALUE_P): New
macro.
(AddExponent): Don't overflow on signed integer multiplication.
(VpCtoV): Don't overflow on signed integer arithmetic.
(VpCtoV): Don't overflow on signed integer arithmetic.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40214 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r-- | bignum.c | 8 |
1 files changed, 6 insertions, 2 deletions
@@ -832,13 +832,17 @@ static VALUE rb_ll2big(LONG_LONG n) { long neg = 0; + unsigned LONG_LONG u; VALUE big; if (n < 0) { - n = -n; + u = 1 + (unsigned LONG_LONG)(-(n + 1)); /* u = -n avoiding overflow */ neg = 1; } - big = rb_ull2big(n); + else { + u = n; + } + big = rb_ull2big(u); if (neg) { RBIGNUM_SET_SIGN(big, 0); } |