* ext/stringio/stringio.c (strio_write): zero fill a gap if exsts.
[ruby-dev:24190] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@6873 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
3d8690ebdb
commit
a838eb5c65
@ -1,3 +1,8 @@
|
|||||||
|
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>
|
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/tcltklib/tcltklib.c (ip_init): cannot create a IP at level 4
|
||||||
|
@ -771,22 +771,24 @@ strio_write(self, str)
|
|||||||
VALUE self, str;
|
VALUE self, str;
|
||||||
{
|
{
|
||||||
struct StringIO *ptr = writable(StringIO(self));
|
struct StringIO *ptr = writable(StringIO(self));
|
||||||
long len;
|
long len, olen;
|
||||||
|
|
||||||
if (TYPE(str) != T_STRING)
|
if (TYPE(str) != T_STRING)
|
||||||
str = rb_obj_as_string(str);
|
str = rb_obj_as_string(str);
|
||||||
len = RSTRING(str)->len;
|
len = RSTRING(str)->len;
|
||||||
if (!len) return INT2FIX(0);
|
if (!len) return INT2FIX(0);
|
||||||
check_modifiable(ptr);
|
check_modifiable(ptr);
|
||||||
|
olen = RSTRING(ptr->string)->len;
|
||||||
if (ptr->flags & STRIO_APPEND) {
|
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);
|
rb_str_cat(ptr->string, RSTRING(str)->ptr, len);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (ptr->pos + len > RSTRING(ptr->string)->len) {
|
if (ptr->pos + len > olen) {
|
||||||
rb_str_resize(ptr->string, ptr->pos + len);
|
rb_str_resize(ptr->string, ptr->pos + len);
|
||||||
|
MEMZERO(RSTRING(ptr->string)->ptr + olen, char, ptr->pos - olen);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
rb_str_modify(ptr->string);
|
rb_str_modify(ptr->string);
|
||||||
|
@ -20,7 +20,7 @@ class TestStringIO < Test::Unit::TestCase
|
|||||||
io.puts "abc"
|
io.puts "abc"
|
||||||
io.truncate(0)
|
io.truncate(0)
|
||||||
io.puts "def"
|
io.puts "def"
|
||||||
assert_equal("\0\0\0def\n", io.string)
|
assert_equal("\0\0\0\0def\n", io.string)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_seek_beyond_eof # [ruby-dev:24194]
|
def test_seek_beyond_eof # [ruby-dev:24194]
|
||||||
|
Loading…
x
Reference in New Issue
Block a user