* io.c (rb_io_readlines, rb_io_each_line): limit must not be zero.

a patch from Tomoyuki Chikanaga at [ruby-dev:42538].  #4024

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@29694 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
nobu 2010-11-04 15:39:07 +00:00
Родитель e2a62c218c
Коммит ee388f6ee2
3 изменённых файлов: 29 добавлений и 0 удалений

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

@ -1,3 +1,8 @@
Fri Nov 5 00:39:00 2010 Nobuyoshi Nakada <nobu@ruby-lang.org>
* io.c (rb_io_readlines, rb_io_each_line): limit must not be zero.
a patch from Tomoyuki Chikanaga at [ruby-dev:42538]. #4024
Fri Nov 5 00:14:15 2010 Aaron Patterson <aaron@tenderlovemaking.com>
* ext/fiddle/extconf.rb: fixing ffi library location on windows.

4
io.c
Просмотреть файл

@ -2724,6 +2724,8 @@ rb_io_readlines(int argc, VALUE *argv, VALUE io)
long limit;
prepare_getline_args(argc, argv, &rs, &limit, io);
if (limit == 0)
rb_raise(rb_eArgError, "invalid limit: 0 for readlines");
ary = rb_ary_new();
while (!NIL_P(line = rb_io_getline_1(rs, limit, io))) {
rb_ary_push(ary, line);
@ -2773,6 +2775,8 @@ rb_io_each_line(int argc, VALUE *argv, VALUE io)
RETURN_ENUMERATOR(io, argc, argv);
prepare_getline_args(argc, argv, &rs, &limit, io);
if (limit == 0)
rb_raise(rb_eArgError, "invalid limit: 0 for each_line");
while (!NIL_P(str = rb_io_getline_1(rs, limit, io))) {
rb_yield(str);
}

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

@ -1702,4 +1702,24 @@ End
GC.start
end
end
def test_readlines_limit_0
bug4024 = '[ruby-dev:42538]'
t = make_tempfile
open(t.path, "r") do |io|
assert_raise(ArgumentError, bug4024) do
io.readlines(0)
end
end
end
def test_each_line_limit_0
bug4024 = '[ruby-dev:42538]'
t = make_tempfile
open(t.path, "r") do |io|
assert_raise(ArgumentError, bug4024) do
io.each_line(0).next
end
end
end
end