aboutsummaryrefslogtreecommitdiffstats
path: root/bignum.c
diff options
context:
space:
mode:
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c7
1 files changed, 4 insertions, 3 deletions
diff --git a/bignum.c b/bignum.c
index db7215ac15..7bcc4c7935 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1210,10 +1210,11 @@ rb_big2ulong(VALUE x)
VALUE num = big2ulong(x, "unsigned long", TRUE);
if (!RBIGNUM_SIGN(x)) {
- if ((long)num < 0) {
+ VALUE v = (VALUE)(-(SIGNED_VALUE)num);
+
+ if (v <= LONG_MAX)
rb_raise(rb_eRangeError, "bignum out of range of unsigned long");
- }
- return (VALUE)(-(SIGNED_VALUE)num);
+ return v;
}
return num;
}