Project

General

Profile

Actions

Bug #19380

closed

IO.read doesn't validate the offset argument

Added by andrykonchin (Andrew Konchin) over 1 year ago. Updated about 1 year ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:112051]

Description

I've noticed that when passed negative offset argument IO.read raises a bit confusing error:

IO.read("read-test.txt", 1, -1)
# (irb):55:in `read': Invalid argument @ rb_io_seek - read-test.txt (Errno::EINVAL)

But error for invalid length argument is much more helpful:

IO.read("read-test.txt", -1)
# (irb):56:in `read': negative length -1 given (ArgumentError)

I would expect a similar ArgumentError exception to be raised for invalid offset argument instead of Invalid argument @ rb_io_seek - read-test.txt (Errno::EINVAL)

Actions

Also available in: Atom PDF

Like0
Like0Like0