summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-17 12:54:26 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2008-08-17 12:54:26 +0000
commit1b91d48bf9059d295edb865b9a6ebbb2c397c617 (patch)
treebc0a4013717fed66329c7ca7ec965812acac0b11
parentd95b92a6f9cf64956d2b54039f519ea5124bc649 (diff)
downloadruby-1b91d48bf9059d295edb865b9a6ebbb2c397c617.tar.gz
ruby-1b91d48bf9059d295edb865b9a6ebbb2c397c617.tar.xz
ruby-1b91d48bf9059d295edb865b9a6ebbb2c397c617.zip
* io.c (prepare_getline_args): io.gets(10,nil) should cause TypeError.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@18675 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r--ChangeLog4
-rw-r--r--io.c34
-rw-r--r--test/ruby/test_io.rb9
3 files changed, 27 insertions, 20 deletions
diff --git a/ChangeLog b/ChangeLog
index d8d80c951..830e54962 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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.
diff --git a/io.c b/io.c
index eb8c808a3..343dd9500 100644
--- a/io.c
+++ b/io.c
@@ -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 d4a51cc8d..0c41847c5 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