mirror of
https://github.com/mruby/mruby
synced 2026-06-08 16:11:16 +00:00
mruby-struct: copied Struct length is not initialized; fix #3114
This commit is contained in:
@@ -418,7 +418,6 @@ static mrb_value
|
||||
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
|
||||
{
|
||||
mrb_value s;
|
||||
mrb_int i, len;
|
||||
|
||||
mrb_get_args(mrb, "o", &s);
|
||||
|
||||
@@ -429,13 +428,7 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
|
||||
if (!mrb_array_p(s)) {
|
||||
mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct");
|
||||
}
|
||||
if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(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]);
|
||||
}
|
||||
mrb_ary_replace(mrb, copy, s);
|
||||
return copy;
|
||||
}
|
||||
|
||||
|
||||
@@ -111,6 +111,14 @@ assert('wrong struct arg count') do
|
||||
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
|
||||
c = Struct.new(:m1, :m2, :m3, :m4, :m5)
|
||||
cc = c.new(1,2,3,4,5)
|
||||
|
||||
Reference in New Issue
Block a user