Skip to content
Permalink
Browse files
mruby-struct: copied Struct length is not initialized; fix #3114
  • Loading branch information
matz committed Feb 19, 2016
1 parent 819c9da commit cf5ca03676e59f28fbc89774d61721f64f52fdf5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
@@ -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 @@
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)

0 comments on commit cf5ca03

Please sign in to comment.