From c204c6b71bad7db3b95484f519f89da26ce7bc02 Mon Sep 17 00:00:00 2001 From: shyouhei Date: Wed, 22 Aug 2007 01:32:19 +0000 Subject: * 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_6@13186 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- bignum.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'bignum.c') diff --git a/bignum.c b/bignum.c index 3517db25d7..f56c7d210b 100644 --- a/bignum.c +++ b/bignum.c @@ -1646,8 +1646,10 @@ rb_big_pow(x, y) yy = FIX2LONG(y); if (yy > 0) { VALUE z = x; + 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; -- cgit v1.2.3