mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[Win32] Negative length IO#sysread
Raise `ArgumentError` in `IO#sysread` on Windows when given a negative length. Fixes [Bug #18880]
This commit is contained in:
parent
472e7b8518
commit
684353fc03
Notes:
git
2022-09-11 23:08:39 +09:00
Merged: https://github.com/ruby/ruby/pull/6354 Merged-By: nobu <nobu@ruby-lang.org>
2 changed files with 10 additions and 1 deletions
3
io.c
3
io.c
|
@ -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);
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in a new issue