Unverified Commit d265c03d authored by ksss's avatar ksss

Fix SEGV when splat object

Splat operation should return an array.
And raise an error if result of convert by to_a is not array or nil.
parent cd5133c5
......@@ -891,15 +891,32 @@ mrb_ary_rindex_m(mrb_state *mrb, mrb_value self)
MRB_API mrb_value
mrb_ary_splat(mrb_state *mrb, mrb_value v)
{
mrb_value a, recv_class;
if (mrb_array_p(v)) {
return v;
}
if (mrb_respond_to(mrb, v, mrb_intern_lit(mrb, "to_a"))) {
return mrb_funcall(mrb, v, "to_a", 0);
if (!mrb_respond_to(mrb, v, mrb_intern_lit(mrb, "to_a"))) {
return mrb_ary_new_from_values(mrb, 1, &v);
}
else {
a = mrb_funcall(mrb, v, "to_a", 0);
if (mrb_array_p(a)) {
return a;
}
else if (mrb_nil_p(a)) {
return mrb_ary_new_from_values(mrb, 1, &v);
}
else {
recv_class = mrb_obj_value(mrb_obj_class(mrb, v));
mrb_raisef(mrb, E_TYPE_ERROR, "can't convert %S to Array (%S#to_a gives %S)",
recv_class,
recv_class,
mrb_obj_value(mrb_obj_class(mrb, a))
);
return mrb_undef_value();
}
}
static mrb_value
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment