From ed94c24944b0014cc89a3b56f76881ccbfa61a1d Mon Sep 17 00:00:00 2001 From: nobu Date: Wed, 10 Dec 2014 07:48:56 +0000 Subject: [PATCH] string.c: term fill * string.c (rb_str_chop_bang): fill wchar terminator. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@48761 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- string.c | 2 +- test/-ext-/string/test_cstr.rb | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/string.c b/string.c index a0e413a267..a526d9b712 100644 --- a/string.c +++ b/string.c @@ -7024,7 +7024,7 @@ rb_str_chop_bang(VALUE str) long len; len = chopped_length(str); STR_SET_LEN(str, len); - RSTRING_PTR(str)[len] = '\0'; + TERM_FILL(&RSTRING_PTR(str)[len], TERM_LEN(str)); if (ENC_CODERANGE(str) != ENC_CODERANGE_7BIT) { ENC_CODERANGE_CLEAR(str); } diff --git a/test/-ext-/string/test_cstr.rb b/test/-ext-/string/test_cstr.rb index a1288373ba..89ab3bb7b0 100644 --- a/test/-ext-/string/test_cstr.rb +++ b/test/-ext-/string/test_cstr.rb @@ -52,6 +52,10 @@ class Test_StringCStr < Test::Unit::TestCase assert_wchars_term_char("a\n") {|s| s.chop!} end + def test_wchar_chomp! + assert_wchars_term_char("a\n") {|s| s.chomp!} + end + def assert_wchars_term_char(str) result = {} WCHARS.map do |enc|