* 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
This commit is contained in:
akr 2013-04-09 11:39:53 +00:00
parent 4329b14cfb
commit 712c7168bf
8 changed files with 105 additions and 53 deletions

View file

@ -5034,15 +5034,14 @@ rb_ary_product(int argc, VALUE *argv, VALUE ary)
else {
/* Compute the length of the result array; return [] if any is empty */
for (i = 0; i < n; i++) {
long k = RARRAY_LEN(arrays[i]), l = resultlen;
long k = RARRAY_LEN(arrays[i]);
if (k == 0) {
result = rb_ary_new2(0);
goto done;
}
resultlen *= k;
if (resultlen < k || resultlen < l || resultlen / k != l) {
if (MUL_OVERFLOW_LONG_P(resultlen, k))
rb_raise(rb_eRangeError, "too big to product");
}
resultlen *= k;
}
result = rb_ary_new2(resultlen);
}