diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-14 07:00:33 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2012-02-14 07:00:33 +0000 |
commit | 52cb46337e9e5bd78f0a64a114ec8004173b2525 (patch) | |
tree | 8ef9995ee193df9225f29b5adcb2ff4029777146 /io.c | |
parent | 799680354ebe7cc7af7fed9766451df27e2f28fc (diff) | |
download | ruby-52cb46337e9e5bd78f0a64a114ec8004173b2525.tar.gz |
* io.c (io_setstrbuf): cut down the buffer if longer.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34592 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'io.c')
-rw-r--r-- | io.c | 11 |
1 files changed, 8 insertions, 3 deletions
@@ -2072,7 +2072,7 @@ io_shift_cbuf(rb_io_t *fptr, int len, VALUE *strp) } static void -io_setstrbuf(VALUE *str,long len) +io_setstrbuf(VALUE *str, long len) { #ifdef _WIN32 len = (len + 1) & ~1L; /* round up for wide char */ @@ -2081,8 +2081,13 @@ io_setstrbuf(VALUE *str,long len) *str = rb_str_new(0, 0); } else { - StringValue(*str); - len -= RSTRING_LEN(*str); + VALUE s = StringValue(*str); + long clen = RSTRING_LEN(s); + if (clen >= len) { + if (clen != len) rb_str_set_len(s, len); + return; + } + len -= clen; } rb_str_modify_expand(*str, len); } |