diff options
| author | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-02-19 11:46:18 +0900 |
|---|---|---|
| committer | Yukihiro "Matz" Matsumoto <[email protected]> | 2016-02-19 11:46:18 +0900 |
| commit | cf5ca03676e59f28fbc89774d61721f64f52fdf5 (patch) | |
| tree | 658104a0b5c5a825d991dca36de7bb901c5e95f4 /mrbgems/mruby-struct | |
| parent | 819c9da8d2b37ed85a4a9213e5d596df5f1e4708 (diff) | |
| download | mruby-cf5ca03676e59f28fbc89774d61721f64f52fdf5.tar.gz mruby-cf5ca03676e59f28fbc89774d61721f64f52fdf5.zip | |
mruby-struct: copied Struct length is not initialized; fix #3114
Diffstat (limited to 'mrbgems/mruby-struct')
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c | 9 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/test/struct.rb | 8 |
2 files changed, 9 insertions, 8 deletions
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index ea91a0436..f084e4031 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -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; } diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb index 0307bb1db..605f23e20 100644 --- a/mrbgems/mruby-struct/test/struct.rb +++ b/mrbgems/mruby-struct/test/struct.rb @@ -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) |
