summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-30 18:12:05 +0000
committernagachika <nagachika@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2014-06-30 18:12:05 +0000
commit428a637f0f7feffd33fed9a984844c6b0d167758 (patch)
tree9f5d407f0557cd3784054afc533ad2f56e9a37e6 /io.c
parent09cf4529269953847723eac4475bfe07c60b028a (diff)
merge revision(s) r46360,r46372: [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_1@46629 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 6deb44187f..e5a4d3b40c 100644
--- a/io.c
+++ b/io.c
@@ -2291,9 +2291,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;
@@ -2320,23 +2317,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);
}
}
@@ -2807,7 +2808,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)