summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--io.c8
-rw-r--r--test/ruby/test_io.rb8
3 files changed, 17 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 569db97..9d1cea8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Fri Jun 6 13:39:32 2014 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (io_setstrbuf, io_read): should not shorten the given buffer until
+ read succeeds. [ruby-core:55951] [Bug #8625]
+
Fri Jun 6 07:41:41 2014 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/psych/lib/psych/visitors/yaml_tree.rb: dump empty symbols with a
diff --git a/io.c b/io.c
index 6926316..653034d 100644
--- a/io.c
+++ b/io.c
@@ -2372,9 +2372,6 @@ io_setstrbuf(VALUE *str, long len)
long clen = RSTRING_LEN(s);
if (clen >= len) {
rb_str_modify(s);
- if (clen != len) {
- rb_str_set_len(s, len);
- }
return;
}
len -= clen;
@@ -2902,7 +2899,10 @@ io_read(int argc, VALUE *argv, VALUE io)
GetOpenFile(io, fptr);
rb_io_check_byte_readable(fptr);
- if (len == 0) return str;
+ if (len == 0) {
+ io_set_read_length(str, 0);
+ return str;
+ }
READ_CHECK(fptr);
#if defined(RUBY_TEST_CRLF_ENVIRONMENT) || defined(_WIN32)
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index dca7860..fab142a 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -1230,6 +1230,14 @@ class TestIO < Test::Unit::TestCase
t.value
assert_equal("", s)
end
+ with_pipe do |r, w|
+ s = "xxx"
+ t = Thread.new {r.read(2, s)}
+ Thread.pass until t.stop?
+ t.kill
+ t.value
+ assert_equal("xxx", s)
+ end
end
def test_write_nonblock