summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-14 07:00:33 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-02-14 07:00:33 +0000
commit52cb46337e9e5bd78f0a64a114ec8004173b2525 (patch)
tree8ef9995ee193df9225f29b5adcb2ff4029777146 /io.c
parent799680354ebe7cc7af7fed9766451df27e2f28fc (diff)
* 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.c11
1 files changed, 8 insertions, 3 deletions
diff --git a/io.c b/io.c
index 541263980e..074d2c50f7 100644
--- a/io.c
+++ b/io.c
@@ -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);
}