summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-10 03:34:38 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-04-10 03:34:38 +0000
commitfa9b5bf223c6dc81ae3f128bfb02a7f69cb7f3b6 (patch)
treeb72f79f9cfe53eaf963bbbeef53330822c3e14d7 /bignum.c
parentea16ec561fb022a204b876be4e3dfb0e08afac58 (diff)
* 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.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/bignum.c b/bignum.c
index 7d4bd3cb17..e709c21c52 100644
--- a/bignum.c
+++ b/bignum.c
@@ -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);
}