diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-12 17:02:48 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-05-12 17:02:48 +0000 |
commit | e95cac18bd9648aa023e390a716c5887155b72b7 (patch) | |
tree | 8952975f0aebd67f57dd6378e9e01e3334985374 | |
parent | 9c38f3e6c333baa5d9321d63b186bd62aad7e56f (diff) | |
download | ruby-e95cac18bd9648aa023e390a716c5887155b72b7.tar.gz |
array.c: check position to insert
* array.c (rb_ary_insert): check position to insert even if no
elements to be inserted. [ruby-core:81125] [Bug #13558]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@58693 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | array.c | 2 | ||||
-rw-r--r-- | test/ruby/test_array.rb | 1 |
2 files changed, 2 insertions, 1 deletions
@@ -1781,8 +1781,8 @@ rb_ary_insert(int argc, VALUE *argv, VALUE ary) rb_check_arity(argc, 1, UNLIMITED_ARGUMENTS); rb_ary_modify_check(ary); - if (argc == 1) return ary; pos = NUM2LONG(argv[0]); + if (argc == 1) return ary; if (pos == -1) { pos = RARRAY_LEN(ary); } diff --git a/test/ruby/test_array.rb b/test/ruby/test_array.rb index d797ee8164..60938937cd 100644 --- a/test/ruby/test_array.rb +++ b/test/ruby/test_array.rb @@ -2121,6 +2121,7 @@ class TestArray < Test::Unit::TestCase assert_equal([0], a.insert(1)) assert_equal([0, 1], a.insert(1, 1)) assert_raise(ArgumentError) { a.insert } + assert_raise(TypeError) { a.insert(Object.new) } assert_equal([0, 1, 2], a.insert(-1, 2)) assert_equal([0, 1, 3, 2], a.insert(-2, 3)) assert_raise(RuntimeError) { [0].freeze.insert(0)} |