[Bug #20325] Enumerator.product.size is 0 if any size is 0

This commit is contained in:
Nobuyoshi Nakada 2024-04-16 16:13:19 +09:00
parent 53a8ad151b
commit 29110fe18d
No known key found for this signature in database
GPG key ID: 3582D74E1FEE4465
2 changed files with 17 additions and 9 deletions

View file

@ -3536,10 +3536,19 @@ static VALUE
enum_product_total_size(VALUE enums)
{
VALUE total = INT2FIX(1);
VALUE sizes = rb_ary_hidden_new(RARRAY_LEN(enums));
long i;
for (i = 0; i < RARRAY_LEN(enums); i++) {
VALUE size = enum_size(RARRAY_AREF(enums, i));
if (size == INT2FIX(0)) {
rb_ary_resize(sizes, 0);
return size;
}
rb_ary_push(sizes, size);
}
for (i = 0; i < RARRAY_LEN(sizes); i++) {
VALUE size = RARRAY_AREF(sizes, i);
if (NIL_P(size) || (RB_TYPE_P(size, T_FLOAT) && isinf(NUM2DBL(size)))) {
return size;