diff options
| author | take_cheeze <[email protected]> | 2014-05-28 23:21:13 +0900 |
|---|---|---|
| committer | take_cheeze <[email protected]> | 2014-05-28 23:21:13 +0900 |
| commit | 32bfa1f15c008628f93c017c7e6e07eb4b3cdeed (patch) | |
| tree | 11f4c799ea256b9b3853f56fcc4db4e5cfd3800e | |
| parent | 7bc4d08f71950f673d788653c50703263edb61df (diff) | |
| download | mruby-32bfa1f15c008628f93c017c7e6e07eb4b3cdeed.tar.gz mruby-32bfa1f15c008628f93c017c7e6e07eb4b3cdeed.zip | |
Add invalid key type check in `Struct#[]=`.
| -rw-r--r-- | mrbgems/mruby-struct/src/struct.c | 2 | ||||
| -rw-r--r-- | mrbgems/mruby-struct/test/struct.rb | 1 |
2 files changed, 2 insertions, 1 deletions
diff --git a/mrbgems/mruby-struct/src/struct.c b/mrbgems/mruby-struct/src/struct.c index adac60202..6894ffec9 100644 --- a/mrbgems/mruby-struct/src/struct.c +++ b/mrbgems/mruby-struct/src/struct.c @@ -672,7 +672,7 @@ mrb_struct_aset(mrb_state *mrb, mrb_value s) return mrb_struct_aset_sym(mrb, s, mrb_symbol(idx), val); } - i = mrb_fixnum(idx); + i = mrb_int(mrb, idx); if (i < 0) i = RSTRUCT_LEN(s) + i; if (i < 0) { mrb_raisef(mrb, E_INDEX_ERROR, diff --git a/mrbgems/mruby-struct/test/struct.rb b/mrbgems/mruby-struct/test/struct.rb index 1e83ec6b3..f4151c493 100644 --- a/mrbgems/mruby-struct/test/struct.rb +++ b/mrbgems/mruby-struct/test/struct.rb @@ -41,6 +41,7 @@ assert('Struct#[]=', '15.2.18.4.3') do cc[:m1] == 3 cc["m2"] = 3 assert_equal 3, cc["m2"] + assert_raise(TypeError) { cc[[]] = 3 } end assert('Struct#each', '15.2.18.4.4') do |
