diff options
| author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-08 09:44:46 +0000 |
|---|---|---|
| committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2004-09-08 09:44:46 +0000 |
| commit | 134fd51203fe569ff0bb98840dea65a3d9b8d639 (patch) | |
| tree | a7c1610b7d2f4fc78f74ec4c118a6480a03e112c /ext/stringio/stringio.c | |
| parent | 84e6661cb308c61912793c4f258d28b8bb777282 (diff) | |
| download | ruby-134fd51203fe569ff0bb98840dea65a3d9b8d639.tar.gz ruby-134fd51203fe569ff0bb98840dea65a3d9b8d639.tar.xz ruby-134fd51203fe569ff0bb98840dea65a3d9b8d639.zip | |
* ext/stringio/stringio.c (strio_write): zero fill a gap if exsts.
[ruby-dev:24190]
git-svn-id: http://svn.ruby-lang.org/repos/ruby/branches/ruby_1_8@6873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/stringio/stringio.c')
| -rw-r--r-- | ext/stringio/stringio.c | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c index 98d3c08ee..98376d06f 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); |
