summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authorkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-14 03:51:56 +0000
committerkosaki <kosaki@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-11-14 03:51:56 +0000
commitd3437b7c1a496143c2bff2698082af143f5e1dc0 (patch)
tree7c042987c63622221ff437b267e73209724a150b /bignum.c
parent11137bed53cc5a3431e2db80e27d31629cca4f0e (diff)
* bignum.c (rb_big2ull): fix off-by-twice bug of NUM2ULL.
* test/-ext-/num2int/test_num2int.rb (class TestNum2int): fix a testcase too. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@33742 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/bignum.c b/bignum.c
index 7bcc4c7935..91c275e605 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1257,8 +1257,14 @@ rb_big2ull(VALUE x)
{
unsigned LONG_LONG num = big2ull(x, "unsigned long long");
- if (!RBIGNUM_SIGN(x))
- return (VALUE)(-(SIGNED_VALUE)num);
+ if (!RBIGNUM_SIGN(x)) {
+ VALUE v = (VALUE)(-(SIGNED_VALUE)num);
+
+ /* FIXNUM_MIN-1 .. LLONG_MIN mapped into 0xbfffffffffffffff .. LONG_MAX+1 */
+ if (v <= LLONG_MAX)
+ rb_raise(rb_eRangeError, "bignum out of range of unsigned long long");
+ return v;
+ }
return num;
}