diff options
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 4 |
1 files changed, 4 insertions, 0 deletions
@@ -2398,23 +2398,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); } } |