summaryrefslogtreecommitdiff
path: root/ext/stringio
diff options
context:
space:
mode:
authorsorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-09 13:01:23 +0000
committersorah <sorah@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-04-09 13:01:23 +0000
commit0a69f2e39de67d3d9887673b5030adcc5f2d0b81 (patch)
tree97d3eedd4703e3db789ed9570fdd7cea31606337 /ext/stringio
parent699c3de19016690c3901641ca3d0d40822558f05 (diff)
* 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
Diffstat (limited to 'ext/stringio')
-rw-r--r--ext/stringio/stringio.c11
1 files changed, 11 insertions, 0 deletions
diff --git a/ext/stringio/stringio.c b/ext/stringio/stringio.c
index da4eb96..609355a 100644
--- a/ext/stringio/stringio.c
+++ b/ext/stringio/stringio.c
@@ -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);
}