mruby-struct: copied Struct length is not initialized; fix #3114

parent 819c9da8
...@@ -418,7 +418,6 @@ static mrb_value ...@@ -418,7 +418,6 @@ static mrb_value
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
{ {
mrb_value s; mrb_value s;
mrb_int i, len;
mrb_get_args(mrb, "o", &s); mrb_get_args(mrb, "o", &s);
...@@ -429,13 +428,7 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy) ...@@ -429,13 +428,7 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
if (!mrb_array_p(s)) { if (!mrb_array_p(s)) {
mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct"); mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct");
} }
if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) { mrb_ary_replace(mrb, copy, s);
mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
}
len = RSTRUCT_LEN(copy);
for (i = 0; i < len; i++) {
mrb_ary_set(mrb, copy, i, RSTRUCT_PTR(s)[i]);
}
return copy; return copy;
} }
......
...@@ -111,6 +111,14 @@ assert('wrong struct arg count') do ...@@ -111,6 +111,14 @@ assert('wrong struct arg count') do
end end
end end
assert('struct dup') do
c = Struct.new(:m1, :m2, :m3, :m4, :m5)
cc = c.new(1,2,3,4,5)
assert_nothing_raised {
assert_equal(cc, cc.dup)
}
end
assert('struct inspect') do assert('struct inspect') do
c = Struct.new(:m1, :m2, :m3, :m4, :m5) c = Struct.new(:m1, :m2, :m3, :m4, :m5)
cc = c.new(1,2,3,4,5) cc = c.new(1,2,3,4,5)
......
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