summaryrefslogtreecommitdiff
path: root/bignum.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-18 07:57:45 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2007-07-18 07:57:45 +0000
commitf2dd1b158e41ecc883954277a12d9b1f447143f6 (patch)
tree92ec61f4224727f5ef47007f219d38929676cae5 /bignum.c
parent0b0046dc2ea34497071e95431c1034a79001e096 (diff)
* bignum.c (rb_big_pow): refine overflow check. [ruby-dev:31242]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@12813 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'bignum.c')
-rw-r--r--bignum.c4
1 files changed, 3 insertions, 1 deletions
diff --git a/bignum.c b/bignum.c
index 5763e8c72f..16fbe86527 100644
--- a/bignum.c
+++ b/bignum.c
@@ -1755,8 +1755,10 @@ rb_big_pow(x, y)
if (yy > 0) {
VALUE z = 0;
long mask;
+ const long BIGLEN_LIMIT = 1024*1024 / SIZEOF_BDIGITS;
- if (RBIGNUM(x)->len * SIZEOF_BDIGITS * yy > 1024*1024) {
+ if ((RBIGNUM(x)->len > BIGLEN_LIMIT) ||
+ (RBIGNUM(x)->len > BIGLEN_LIMIT / yy)) {
rb_warn("in a**b, b may be too big");
d = (double)yy;
break;