From 0bbd60b52348a9c1938d8cce7a1d5aea996e7e1e Mon Sep 17 00:00:00 2001 From: ksss Date: Sun, 21 May 2017 22:55:28 +0900 Subject: IO#sysread should raise error when invalid pos --- src/io.c | 2 +- test/io.rb | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/io.c b/src/io.c index f15f182f2..7a1121338 100644 --- a/src/io.c +++ b/src/io.c @@ -623,7 +623,7 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io) mrb_get_args(mrb, "i|S", &maxlen, &buf); if (maxlen < 0) { - return mrb_nil_value(); + mrb_raise(mrb, E_ARGUMENT_ERROR, "negative expanding string size"); } else if (maxlen == 0) { return mrb_str_new(mrb, NULL, maxlen); diff --git a/test/io.rb b/test/io.rb index 02ab038bb..9ce8985f7 100644 --- a/test/io.rb +++ b/test/io.rb @@ -236,6 +236,7 @@ assert('IO.sysopen, IO#sysread') do io.close assert_equal "", io.sysread(0) assert_raise(IOError) { io.sysread(1) } + assert_raise(ArgumentError) { io.sysread(-1) } io.closed? end -- cgit v1.2.3