aboutsummaryrefslogtreecommitdiffstats
path: root/array.c
diff options
context:
space:
mode:
Diffstat (limited to 'array.c')
-rw-r--r--array.c7
1 files changed, 3 insertions, 4 deletions
diff --git a/array.c b/array.c
index 76a3a6279d..2646e904e7 100644
--- a/array.c
+++ b/array.c
@@ -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);
}