aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_string.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-17 11:24:09 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2016-02-17 11:24:09 +0000
commitd29e11d70080e89330a1306913b5197f29dc8111 (patch)
tree89388b2f055743605308c11f382a87f40d8b2097 /test/ruby/test_string.rb
parent648bf74fa2eea99496f000f5e3c00e3a9115ce54 (diff)
downloadruby-d29e11d70080e89330a1306913b5197f29dc8111.tar.gz
string.c: fix rb_str_init
* string.c (rb_str_init): fix segfault and memory leak, consider wide char encoding terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@53855 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/ruby/test_string.rb')
-rw-r--r--test/ruby/test_string.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_string.rb b/test/ruby/test_string.rb
index c78ecc1d6c..4df5f4f841 100644
--- a/test/ruby/test_string.rb
+++ b/test/ruby/test_string.rb
@@ -70,6 +70,24 @@ class TestString < Test::Unit::TestCase
assert_raise(RuntimeError){ str.__send__(:initialize, 'abc', capacity: 1000, encoding: 'euc-jp') }
end
+ def test_initialize_nonstring
+ assert_raise(TypeError) {
+ S(1)
+ }
+ assert_raise(TypeError) {
+ S(1, capacity: 1000)
+ }
+ end
+
+ def test_initialize_memory_leak
+ assert_no_memory_leak([], <<-PREP, <<-CODE, rss: true)
+code = proc {('x'*100000).__send__(:initialize, '')}
+1_000.times(&code)
+PREP
+100_000.times(&code)
+CODE
+ end
+
def test_AREF # '[]'
assert_equal("A", S("AooBar")[0])
assert_equal("B", S("FooBaB")[-1])