GitHub

File tree

  • mrbgems/mruby-array-ext/src

Original file line numberDiff line numberDiff line change

@@ -1395,9 +1395,15 @@ ary_product_group(mrb_state *mrb, mrb_value self_ary)

13951395

mrb_value a = RARRAY_PTR(arys_ary)[j]; // arys[j]

13961396

mrb_check_type(mrb, a, MRB_TT_ARRAY);

13971397

mrb_int b = RARRAY_LEN(a); // a.size

1398+

if (b <= 0) {

1399+

mrb_raise(mrb, E_ARGUMENT_ERROR, "cannot compute product with an empty array");

1400+

}

13981401

mrb_ary_set(mrb, group, j + 1, RARRAY_PTR(a)[n % b]);

13991402

n /= b;

14001403

}

1404+

if (n >= RARRAY_LEN(self_ary)) {

1405+

mrb_raise(mrb, E_INDEX_ERROR, "index out of range");

1406+

}

14011407

mrb_ary_set(mrb, group, 0, RARRAY_PTR(self_ary)[n]);

14021408
14031409

return group;

Read the original on github.com ↗