summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog11
-rw-r--r--ext/stringio/stringio.c10
-rw-r--r--test/stringio/test_stringio.rb2
3 files changed, 15 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 8d3c17c3fb..d278bd0b1e 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,14 +1,19 @@
+Wed Sep 8 18:44:03 2004 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * ext/stringio/stringio.c (strio_write): zero fill a gap if exsts.
+ [ruby-dev:24190]
+
Wed Sep 8 15:19:49 2004 Hidetoshi NAGAI <nagai@ai.kyutech.ac.jp>
* ext/tcltklib/tcltklib.c (ip_init): cannot create a IP at level 4
- * ext/tk/lib/multi-tk.rb: improve 'exit' operation, security check,
+ * ext/tk/lib/multi-tk.rb: improve 'exit' operation, security check,
and error treatment
* ext/tk/lib/multi-tk.rb: allow a trusted slave IP to create slave IPs
- * ext/tk/lib/tk/listbox.rb: add TkListbox#value, value=, clear, and
- erase
+ * ext/tk/lib/tk/listbox.rb: add TkListbox#value, value=, clear, and
+ erase
* ext/tk/lib/tk/text.rb: add TkText#clear and erase
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index 98d3c08ee5..98376d06f8 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -771,22 +771,24 @@ strio_write(self, str)
VALUE self, str;
{
struct StringIO *ptr = writable(StringIO(self));
- long len;
+ long len, olen;
if (TYPE(str) != T_STRING)
str = rb_obj_as_string(str);
len = RSTRING(str)->len;
if (!len) return INT2FIX(0);
check_modifiable(ptr);
+ olen = RSTRING(ptr->string)->len;
if (ptr->flags & STRIO_APPEND) {
- ptr->pos = RSTRING(ptr->string)->len;
+ ptr->pos = olen;
}
- if (ptr->pos == RSTRING(ptr->string)->len) {
+ if (ptr->pos == olen) {
rb_str_cat(ptr->string, RSTRING(str)->ptr, len);
}
else {
- if (ptr->pos + len > RSTRING(ptr->string)->len) {
+ if (ptr->pos + len > olen) {
rb_str_resize(ptr->string, ptr->pos + len);
+ MEMZERO(RSTRING(ptr->string)->ptr + olen, char, ptr->pos - olen);
}
else {
rb_str_modify(ptr->string);
diff --git a/test/stringio/test_stringio.rb b/test/stringio/test_stringio.rb
index cdb35e6acc..fee305e856 100644
--- a/test/stringio/test_stringio.rb
+++ b/test/stringio/test_stringio.rb
@@ -20,7 +20,7 @@ class TestStringIO < Test::Unit::TestCase
io.puts "abc"
io.truncate(0)
io.puts "def"
- assert_equal("\0\0\0def\n", io.string)
+ assert_equal("\0\0\0\0def\n", io.string)
end
def test_seek_beyond_eof # [ruby-dev:24194]