diff options
| -rw-r--r-- | src/io.c | 3 | ||||
| -rw-r--r-- | test/io.rb | 5 |
2 files changed, 8 insertions, 0 deletions
@@ -637,6 +637,9 @@ mrb_io_sysread(mrb_state *mrb, mrb_value io) } fptr = (struct mrb_io *)io_get_open_fptr(mrb, io); + if (!fptr->readable) { + mrb_raise(mrb, E_IO_ERROR, "not opened for reading"); + } ret = read(fptr->fd, RSTRING_PTR(buf), maxlen); switch (ret) { case 0: /* EOF */ diff --git a/test/io.rb b/test/io.rb index 9ce8985f7..ee4309b57 100644 --- a/test/io.rb +++ b/test/io.rb @@ -238,6 +238,11 @@ assert('IO.sysopen, IO#sysread') do assert_raise(IOError) { io.sysread(1) } assert_raise(ArgumentError) { io.sysread(-1) } io.closed? + + fd = IO.sysopen $mrbtest_io_wfname, "w" + io = IO.new fd, "w" + assert_raise(IOError) { io.sysread(1) } + io.close end assert('IO.sysopen, IO#syswrite') do |
