From 712c7168bf55f61df33efa2a7552e4b3c25b306c Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 9 Apr 2013 11:39:53 +0000 Subject: * internal.h (MUL_OVERFLOW_SIGNED_INTEGER_P): New macro. (MUL_OVERFLOW_FIXNUM_P): Ditto. (MUL_OVERFLOW_LONG_P): Ditto. * array.c (rb_ary_product): Don't overflow on signed integer multiplication. * numeric.c (fix_mul): Ditto. (int_pow): Ditto. * rational.c (f_imul): Ditto. * insns.def (opt_mult): Ditto. * thread.c (sleep_timeval): Don't overflow on signed integer addition. * bignum.c (rb_int2big): Don't overflow on signed integer negation. (rb_big2ulong): Ditto. (rb_big2long): Ditto. (rb_big2ull): Ditto. (rb_big2ll): Ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@40208 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- numeric.c | 14 +++++--------- 1 file changed, 5 insertions(+), 9 deletions(-) (limited to 'numeric.c') diff --git a/numeric.c b/numeric.c index 66820eeed1..d142c67138 100644 --- a/numeric.c +++ b/numeric.c @@ -2731,7 +2731,6 @@ fix_mul(VALUE x, VALUE y) #if SIZEOF_LONG * 2 <= SIZEOF_LONG_LONG LONG_LONG d; #else - volatile long c; VALUE r; #endif @@ -2745,13 +2744,11 @@ fix_mul(VALUE x, VALUE y) #else if (FIT_SQRT_LONG(a) && FIT_SQRT_LONG(b)) return LONG2FIX(a*b); - c = a * b; - r = LONG2FIX(c); - if (a == 0) return x; - if (FIX2LONG(r) != c || c/a != b) { + if (MUL_OVERFLOW_FIXNUM_P(a, b)) r = rb_big_mul(rb_int2big(a), rb_int2big(b)); - } + else + r = LONG2FIX(a * b); return r; #endif } @@ -2973,11 +2970,10 @@ int_pow(long x, unsigned long y) y >>= 1; } { - volatile long xz = x * z; - if (!POSFIXABLE(xz) || xz / x != z) { + if (MUL_OVERFLOW_FIXNUM_P(x, z)) { goto bignum; } - z = xz; + z = x * z; } } while (--y); if (neg) z = -z; -- cgit v1.2.3