From 9d170963098fea8e11196cee155ca448bfc01fb3 Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 10 Dec 2014 07:49:10 +0000 Subject: [PATCH] string.c: term fill * string.c (rb_str_splice_0): fill wchar terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48762 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 4 ++-- test/-ext-/string/test_cstr.rb | 4 ++++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/string.c b/string.c index a526d9b712..49e3c18152 100644 --- a/string.c +++ b/string.c @@ -3709,7 +3709,7 @@ rb_str_splice_0(VALUE str, long beg, long len, VALUE val) RSTRING_GETMEM(str, sptr, slen); if (len < vlen) { /* expand string */ - RESIZE_CAPA(str, slen + vlen - len + TERM_LEN(str)); + RESIZE_CAPA(str, slen + vlen - len); sptr = RSTRING_PTR(str); } @@ -3726,7 +3726,7 @@ rb_str_splice_0(VALUE str, long beg, long len, VALUE val) } slen += vlen - len; STR_SET_LEN(str, slen); - sptr[slen] = '\0'; + TERM_FILL(&sptr[slen], TERM_LEN(str)); OBJ_INFECT(str, val); } diff --git a/test/-ext-/string/test_cstr.rb b/test/-ext-/string/test_cstr.rb index 89ab3bb7b0..a7cb0ebe9c 100644 --- a/test/-ext-/string/test_cstr.rb +++ b/test/-ext-/string/test_cstr.rb @@ -56,6 +56,10 @@ class Test_StringCStr < Test::Unit::TestCase assert_wchars_term_char("a\n") {|s| s.chomp!} end + def test_wchar_aset + assert_wchars_term_char("a"*30) {|s| s[29,1] = ""} + end + def assert_wchars_term_char(str) result = {} WCHARS.map do |enc|