mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
io.c: buffer must be modifiable
* io.c (io_setstrbuf): always check if the buffer is modifiable. [ruby-core:62643] [Bug #9847] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@45979 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
e279eca4bd
commit
831202f85c
3 changed files with 11 additions and 7 deletions
|
@ -1,3 +1,8 @@
|
||||||
|
Sun May 18 08:22:25 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||||
|
|
||||||
|
* 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@fsij.org>
|
Sun May 18 01:21:23 2014 Tanaka Akira <akr@fsij.org>
|
||||||
|
|
||||||
* include/ruby/ruby.h: Hide Rational internal.
|
* include/ruby/ruby.h: Hide Rational internal.
|
||||||
|
|
2
io.c
2
io.c
|
@ -2370,8 +2370,8 @@ io_setstrbuf(VALUE *str, long len)
|
||||||
VALUE s = StringValue(*str);
|
VALUE s = StringValue(*str);
|
||||||
long clen = RSTRING_LEN(s);
|
long clen = RSTRING_LEN(s);
|
||||||
if (clen >= len) {
|
if (clen >= len) {
|
||||||
if (clen != len) {
|
|
||||||
rb_str_modify(s);
|
rb_str_modify(s);
|
||||||
|
if (clen != len) {
|
||||||
rb_str_set_len(s, len);
|
rb_str_set_len(s, len);
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
|
@ -2839,25 +2839,24 @@ End
|
||||||
|
|
||||||
def assert_buffer_not_raise_shared_string_error
|
def assert_buffer_not_raise_shared_string_error
|
||||||
bug6764 = '[ruby-core:46586]'
|
bug6764 = '[ruby-core:46586]'
|
||||||
|
bug9847 = '[ruby-core:62643] [Bug #9847]'
|
||||||
size = 28
|
size = 28
|
||||||
data = [*"a".."z", *"A".."Z"].shuffle.join("")
|
data = [*"a".."z", *"A".."Z"].shuffle.join("")
|
||||||
t = Tempfile.new("test_io")
|
t = Tempfile.new("test_io")
|
||||||
t.write(data)
|
t.write(data)
|
||||||
t.close
|
t.close
|
||||||
w = Tempfile.new("test_io")
|
w = []
|
||||||
assert_nothing_raised(RuntimeError, bug6764) do
|
assert_nothing_raised(RuntimeError, bug6764) do
|
||||||
File.open(t.path, "r") do |r|
|
|
||||||
buf = ''
|
buf = ''
|
||||||
|
File.open(t.path, "r") do |r|
|
||||||
while yield(r, size, buf)
|
while yield(r, size, buf)
|
||||||
w << buf
|
w << buf.dup
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
w.close
|
assert_equal(data, w.join(""), bug9847)
|
||||||
assert_equal(data, w.open.read, bug6764)
|
|
||||||
ensure
|
ensure
|
||||||
t.close!
|
t.close!
|
||||||
w.close!
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_read_buffer_not_raise_shared_string_error
|
def test_read_buffer_not_raise_shared_string_error
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue