Skip to content

Commit cf5ca03

Browse files
committed
mruby-struct: copied Struct length is not initialized; fix #3114
1 parent 819c9da commit cf5ca03

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

mrbgems/mruby-struct/src/struct.c

+1-8
Original file line numberDiff line numberDiff line change
@@ -418,7 +418,6 @@ static mrb_value
418418
mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
419419
{
420420
mrb_value s;
421-
mrb_int i, len;
422421

423422
mrb_get_args(mrb, "o", &s);
424423

@@ -429,13 +428,7 @@ mrb_struct_init_copy(mrb_state *mrb, mrb_value copy)
429428
if (!mrb_array_p(s)) {
430429
mrb_raise(mrb, E_TYPE_ERROR, "corrupted struct");
431430
}
432-
if (RSTRUCT_LEN(copy) != RSTRUCT_LEN(s)) {
433-
mrb_raise(mrb, E_TYPE_ERROR, "struct size mismatch");
434-
}
435-
len = RSTRUCT_LEN(copy);
436-
for (i = 0; i < len; i++) {
437-
mrb_ary_set(mrb, copy, i, RSTRUCT_PTR(s)[i]);
438-
}
431+
mrb_ary_replace(mrb, copy, s);
439432
return copy;
440433
}
441434

mrbgems/mruby-struct/test/struct.rb

+8
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,14 @@
111111
end
112112
end
113113

114+
assert('struct dup') do
115+
c = Struct.new(:m1, :m2, :m3, :m4, :m5)
116+
cc = c.new(1,2,3,4,5)
117+
assert_nothing_raised {
118+
assert_equal(cc, cc.dup)
119+
}
120+
end
121+
114122
assert('struct inspect') do
115123
c = Struct.new(:m1, :m2, :m3, :m4, :m5)
116124
cc = c.new(1,2,3,4,5)

0 commit comments

Comments
 (0)