* ext/stringio/stringio.c (strio_each, strio_readlines):

limit must not be zero. Fixes [ruby-dev:43392].

* test/stringio/test_stringio.rb: Add tests for above.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31252 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
sorah 2011-04-09 13:01:23 +00:00
Родитель 699c3de190
Коммит 0a69f2e39d
3 изменённых файлов: 26 добавлений и 0 удалений

Просмотреть файл

@ -1,3 +1,10 @@
Sat Apr 9 21:54:15 2011 Shota Fukumori <sorah@tubusu.net>
* ext/stringio/stringio.c (strio_each, strio_readlines):
limit must not be zero. Fixes [ruby-dev:43392].
* test/stringio/test_stringio.rb: Add tests for above.
Sat Apr 9 18:01:36 2011 Tanaka Akira <akr@fsij.org>
* include/ruby/util.h: parenthesize macro arguments.

Просмотреть файл

@ -1067,6 +1067,11 @@ strio_each(int argc, VALUE *argv, VALUE self)
struct StringIO *ptr = StringIO(self);
VALUE line;
if(argc > 0 && TYPE(argv[argc-1]) == T_FIXNUM &&
FIX2INT(argv[argc-1]) == 0) {
rb_raise(rb_eArgError, "invalid limit: 0 for readlines");
}
RETURN_ENUMERATOR(self, argc, argv);
while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
@ -1088,6 +1093,12 @@ strio_readlines(int argc, VALUE *argv, VALUE self)
{
struct StringIO *ptr = StringIO(self);
VALUE ary = rb_ary_new(), line;
if(argc > 0 && TYPE(argv[argc-1]) == T_FIXNUM &&
FIX2INT(argv[argc-1]) == 0) {
rb_raise(rb_eArgError, "invalid limit: 0 for readlines");
}
while (!NIL_P(line = strio_getline(argc, argv, readable(ptr)))) {
rb_ary_push(ary, line);
}

Просмотреть файл

@ -482,4 +482,12 @@ class TestStringIO < Test::Unit::TestCase
assert_raise(RuntimeError, bug) {s.string = "foo"}
assert_raise(RuntimeError, bug) {s.reopen("")}
end
def test_readlines_limit_0
assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.readlines(0) }
end
def test_each_line_limit_0
assert_raise(ArgumentError, "[ruby-dev:43392]") { StringIO.new.each_line(0) }
end
end