diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-17 12:54:26 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2008-08-17 12:54:26 +0000 |
commit | 0ff4061ef7e3a8ffa681698fa8490740616d1aac (patch) | |
tree | bc0a4013717fed66329c7ca7ec965812acac0b11 | |
parent | 59491ed3b06481a3991aca84aebb5e55e5a12edd (diff) | |
download | ruby-0ff4061ef7e3a8ffa681698fa8490740616d1aac.tar.gz |
* io.c (prepare_getline_args): io.gets(10,nil) should cause TypeError.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@18675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | ChangeLog | 4 | ||||
-rw-r--r-- | io.c | 34 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 9 |
3 files changed, 27 insertions, 20 deletions
@@ -1,3 +1,7 @@ +Sun Aug 17 21:50:22 2008 Tanaka Akira <akr@fsij.org> + + * io.c (prepare_getline_args): io.gets(10,nil) should cause TypeError. + Sun Aug 17 15:58:39 2008 Nobuyoshi Nakada <nobu@ruby-lang.org> * lib/mkmf.rb: not check config.h. @@ -1889,29 +1889,23 @@ rb_io_getline_fast(rb_io_t *fptr, rb_encoding *enc) static void prepare_getline_args(int argc, VALUE *argv, VALUE *rsp, long *limit, VALUE io) { - VALUE lim, rs; + VALUE rs = rb_rs, lim = Qnil; rb_io_t *fptr; - if (argc == 0) { - rs = rb_rs; - lim = Qnil; - } - else { - rb_scan_args(argc, argv, "11", &rs, &lim); - if (!NIL_P(lim)) { - StringValue(rs); - } - else if (!NIL_P(rs) && TYPE(rs) != T_STRING) { - VALUE tmp = rb_check_string_type(rs); + if (argc == 1) { + VALUE tmp = Qnil; - if (NIL_P(tmp)) { - lim = rs; - rs = rb_rs; - } - else { - rs = tmp; - } - } + if (NIL_P(argv[0]) || !NIL_P(tmp = rb_check_string_type(argv[0]))) { + rs = tmp; + } + else { + lim = argv[0]; + } + } + else if (2 <= argc) { + rb_scan_args(argc, argv, "2", &rs, &lim); + if (!NIL_P(rs)) + StringValue(rs); } if (!NIL_P(rs)) { rb_encoding *enc_rs, *enc_io; diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index d4a51cc8dc..0c41847c52 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -44,6 +44,15 @@ class TestIO < Test::Unit::TestCase r.close end + def test_gets_limit_extra_arg + with_pipe {|r, w| + r, w = IO.pipe + w << "0123456789" + w.close + assert_raise(TypeError) { r.gets(3,nil) } + } + end + # This test cause SEGV. def test_ungetc r, w = IO.pipe |