mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
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:
parent
73b59166d2
commit
622f3f14b6
3 changed files with 15 additions and 0 deletions
|
@ -1,3 +1,8 @@
|
|||
Mon Jan 26 11:37:49 2015 Dave Stevens <dave@crowdlab.com>
|
||||
|
||||
* string.c (str_make_independent_expand): terminate String when
|
||||
moved from heap to embedded. [Fix GH-821].
|
||||
|
||||
Sun Jan 25 12:04:12 2015 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* array.c (flatten): no need to call to_ary method on elements
|
||||
|
|
1
string.c
1
string.c
|
@ -1593,6 +1593,7 @@ str_make_independent_expand(VALUE str, long expand)
|
|||
ptr = RSTRING(str)->as.heap.ptr;
|
||||
STR_SET_EMBED(str);
|
||||
memcpy(RSTRING(str)->as.ary, ptr, len);
|
||||
RSTRING(str)->as.ary[len] = '\0'; /* Ensure string is terminated */
|
||||
STR_SET_EMBED_LEN(str, len);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -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|
|
||||
|
|
Loading…
Reference in a new issue