summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authorusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-07 03:43:19 +0000
committerusa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-07-07 03:43:19 +0000
commitae8a4a434498d0a65ec1e9428714123203e981c6 (patch)
treebee6a49192b3ff1f4be2f6ed50d49b8097074d34 /io.c
parent20666f4a4dcba1895cd083c379cd48e98e036631 (diff)
merge revision(s) 46360,46372: [Backport #8625]
* io.c (io_setstrbuf, io_read): should not shorten the given buffer until read succeeds. [ruby-core:55951] [Bug #8625] * io.c (read_all): truncate the buffer before appending read data, instead of truncating before reading. [ruby-core:55951] [Bug #8625] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_0_0@46738 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r--io.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/io.c b/io.c
index d676bb1979..13987e1b84 100644
--- a/io.c
+++ b/io.c
@@ -2254,9 +2254,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;
@@ -2283,23 +2280,27 @@ read_all(rb_io_t *fptr, long siz, VALUE str)
int cr;
if (NEED_READCONV(fptr)) {
+ int first = !NIL_P(str);
SET_BINARY_MODE(fptr);
io_setstrbuf(&str,0);
make_readconv(fptr, 0);
while (1) {
VALUE v;
if (fptr->cbuf.len) {
+ if (first) rb_str_set_len(str, first = 0);
io_shift_cbuf(fptr, fptr->cbuf.len, &str);
}
v = fill_cbuf(fptr, 0);
if (v != MORE_CHAR_SUSPENDED && v != MORE_CHAR_FINISHED) {
if (fptr->cbuf.len) {
+ if (first) rb_str_set_len(str, first = 0);
io_shift_cbuf(fptr, fptr->cbuf.len, &str);
}
rb_exc_raise(v);
}
if (v == MORE_CHAR_FINISHED) {
clear_readconv(fptr);
+ if (first) rb_str_set_len(str, first = 0);
return io_enc_str(str, fptr);
}
}
@@ -2727,7 +2728,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)