From 5a6a502ef9d88a77f701be8e0dde8fa489eb1e1f Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 17 Feb 2016 11:24:09 +0000 Subject: 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 --- test/ruby/test_string.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test') 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]) -- cgit v1.2.3