diff options
-rw-r--r-- | io.c | 3 | ||||
-rw-r--r-- | test/ruby/test_io.rb | 8 |
2 files changed, 10 insertions, 1 deletions
@@ -3053,7 +3053,8 @@ static int io_setstrbuf(VALUE *str, long len) { #ifdef _WIN32 - len = (len + 1) & ~1L; /* round up for wide char */ + if (len > 0) + len = (len + 1) & ~1L; /* round up for wide char */ #endif if (NIL_P(*str)) { *str = rb_str_new(0, len); diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index d6fcf16ddd..f791b4415d 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -2213,6 +2213,14 @@ class TestIO < Test::Unit::TestCase end) end + def test_sysread_with_negative_length + make_tempfile {|t| + open(t.path) do |f| + assert_raise(ArgumentError) { f.sysread(-1) } + end + } + end + def test_flag make_tempfile {|t| assert_raise(ArgumentError) do |