summaryrefslogtreecommitdiff
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
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
-rw-r--r--ChangeLog4
-rw-r--r--io.c11
2 files changed, 12 insertions, 3 deletions
diff --git a/ChangeLog b/ChangeLog
index 45e89d1ba7..fdfd848ebf 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+Tue Feb 14 16:00:30 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (io_setstrbuf): cut down the buffer if longer.
+
Tue Feb 14 15:06:37 2012 Nobuyoshi Nakada <nobu@ruby-lang.org>
* lib/test/unit/assertions.rb (build_message): skip escaped
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);
}