summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
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;
}