string.c: terminate when embedded

* string.c (str_make_independent_expand): terminate String when
  moved from heap to embedded.  [Fix GH-821].

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49405 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2015-01-26 02:37:51 +00:00
parent 73b59166d2
commit 622f3f14b6
3 changed files with 15 additions and 0 deletions

View file

@ -86,6 +86,15 @@ class Test_StringCStr < Test::Unit::TestCase
}
end
def test_embedded_from_heap
gh821 = "[GH-821]"
embedded_string = "abcdefghi"
string = embedded_string.gsub("efg", "123")
{}[string] = 1
non_terminated = "#{string}#{nil}"
assert_nil(Bug::String.cstr_term_char(non_terminated), gh821)
end
def assert_wchars_term_char(str)
result = {}
WCHARS.map do |enc|