From: sheepman Date: 2005-02-02T21:14:12+09:00 Subject: [ruby-dev:25618] StringIO#truncate doesn't memzero an extended part こんばんは、sheepman です。 StringIO#truncate に size よりも大きな数字を与えた時にバッファに加えられる 領域が MEMZERO されていません。 $ ruby -rstringio -ve ' sio = StringIO.new("hoge") sio.truncate(20) p sio.string ' ruby 1.9.0 (2005-01-27) [i686-linux] "hoge\000\000\000\000\000\000\000\000)\010\000\000\000\000\000\000" rb_str_resize が MEMZERO を呼ぶべきという気もしますが。 以下はパッチです。 * ext/stringio/stringio.c (strio_truncate) should MEMZERO an extended part. Index: stringio.c =================================================================== RCS file: /src/ruby/ext/stringio/stringio.c,v retrieving revision 1.37 diff -u -1 -r1.37 stringio.c --- stringio.c 6 Dec 2004 08:40:30 -0000 1.37 +++ stringio.c 2 Feb 2005 05:17:48 -0000 @@ -936,2 +936,3 @@ long l = NUM2LONG(len); + long plen = RSTRING(string)->len; if (l < 0) { @@ -940,2 +941,5 @@ rb_str_resize(string, l); + if ( plen < l ){ + MEMZERO(RSTRING(string)->ptr + plen, char, l - plen ); + } return len; -- sheepman / TAMURA Takashi sheepman@tcn.zaq.ne.jp http://sheepman.parfait.ne.jp/