ruby-changes:33898
From: nobu <ko1@a...>
Date: Sun, 18 May 2014 08:22:34 +0900 (JST)
Subject: [ruby-changes:33898] nobu:r45979 (trunk): io.c: buffer must be modifiable
nobu 2014-05-18 08:22:28 +0900 (Sun, 18 May 2014) New Revision: 45979 http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=45979 Log: io.c: buffer must be modifiable * io.c (io_setstrbuf): always check if the buffer is modifiable. [ruby-core:62643] [Bug #9847] Modified files: trunk/ChangeLog trunk/io.c trunk/test/ruby/test_io.rb Index: ChangeLog =================================================================== --- ChangeLog (revision 45978) +++ ChangeLog (revision 45979) @@ -1,3 +1,8 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1 +Sun May 18 08:22:25 2014 Nobuyoshi Nakada <nobu@r...> + + * io.c (io_setstrbuf): always check if the buffer is modifiable. + [ruby-core:62643] [Bug #9847] + Sun May 18 01:21:23 2014 Tanaka Akira <akr@f...> * include/ruby/ruby.h: Hide Rational internal. Index: io.c =================================================================== --- io.c (revision 45978) +++ io.c (revision 45979) @@ -2370,8 +2370,8 @@ io_setstrbuf(VALUE *str, long len) https://github.com/ruby/ruby/blob/trunk/io.c#L2370 VALUE s = StringValue(*str); long clen = RSTRING_LEN(s); if (clen >= len) { + rb_str_modify(s); if (clen != len) { - rb_str_modify(s); rb_str_set_len(s, len); } return; Index: test/ruby/test_io.rb =================================================================== --- test/ruby/test_io.rb (revision 45978) +++ test/ruby/test_io.rb (revision 45979) @@ -2839,25 +2839,24 @@ End https://github.com/ruby/ruby/blob/trunk/test/ruby/test_io.rb#L2839 def assert_buffer_not_raise_shared_string_error bug6764 = '[ruby-core:46586]' + bug9847 = '[ruby-core:62643] [Bug #9847]' size = 28 data = [*"a".."z", *"A".."Z"].shuffle.join("") t = Tempfile.new("test_io") t.write(data) t.close - w = Tempfile.new("test_io") + w = [] assert_nothing_raised(RuntimeError, bug6764) do + buf = '' File.open(t.path, "r") do |r| - buf = '' while yield(r, size, buf) - w << buf + w << buf.dup end end end - w.close - assert_equal(data, w.open.read, bug6764) + assert_equal(data, w.join(""), bug9847) ensure t.close! - w.close! end def test_read_buffer_not_raise_shared_string_error -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/