summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 07:06:21 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2004-11-29 07:06:21 +0000
commita70f475dbbdd0e8f2b14d98aefc3d01fc5af3d17 (patch)
tree0184e51b6430722c8543fa674f6089477b6399d2
parenta229d2e740d21e46d42dd43a095a38f707c42396 (diff)
* ext/stringio/stringio.c (strio_write): insufficiently filled string
being extended when overwriting. [ruby-core:03836] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@7417 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog5
-rw-r--r--ext/stringio/stringio.c2
-rw-r--r--test/stringio/test_stringio.rb10
3 files changed, 16 insertions, 1 deletions
diff --git a/ChangeLog b/ChangeLog
index 6c5770a184..f9e87ee9c7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Mon Nov 29 16:06:04 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/stringio/stringio.c (strio_write): insufficiently filled string
+ being extended when overwriting. [ruby-core:03836]
+
Mon Nov 29 15:22:28 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
* test/io/nonblock/test_flush.rb: abandon tests when io/nonblock is
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 09ecc6926e..8750262c11 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -794,7 +794,7 @@ strio_write(self, str)
else {
if (ptr->pos + len > olen) {
rb_str_resize(ptr->string, ptr->pos + len);
- MEMZERO(RSTRING(ptr->string)->ptr + olen, char, ptr->pos - olen);
+ MEMZERO(RSTRING(ptr->string)->ptr + olen, char, ptr->pos + len - olen);
}
else {
rb_str_modify(ptr->string);
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index fee305e856..de15ab5508 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -30,4 +30,14 @@ class TestStringIO < Test::Unit::TestCase
io.print "last"
assert_equal("\0" * n + "last", io.string)
end
+
+ def test_overwrite # [ruby-core:03836]
+ stringio = StringIO.new
+ responses = ['', 'just another ruby', 'hacker']
+ responses.each do |resp|
+ stringio.puts(resp)
+ stringio.rewind
+ end
+ assert_equal("hacker\nother ruby\n", stringio.string)
+ end
end