Project

General

Profile

Actions

Bug #22433

open

IO#sysread and IO#pread are inconsistent for length 0 and negative numbers

Bug #22433: IO#sysread and IO#pread are inconsistent for length 0 and negative numbers

Added by rhenium (Kazuki Yamaguchi) about 21 hours ago. Updated about 21 hours ago.

Status:
Open
Assignee:
-
Target version:
-
[ruby-core:127092]

Description

When the length is 0 and an output buffer is given, the buffer is not cleared correctly. [Bug #18421] fixed the same bug for IO#readpartial and IO#read_nonblock, but it omitted IO#sysread and IO#pread:

File.open("/dev/null"){|f|f.read(0,"abc")} #=> ""

# Returns the buffer unmodified
File.open("/dev/null"){|f|f.sysread(0,"abc")} #=> "abc"
File.open("/dev/null"){|f|f.pread(0,0,"abc")} #=> "abc"

These methods should also reject negative lengths:

File.open("/dev/null"){|f|f.read(-1,"abc")} # ArgumentError "negative length -1 given"

# Tries to read (size_t)-1 bytes
File.open("/dev/null"){|f|f.sysread(-1,"abc")} # Errno::EFAULT
File.open("/dev/null"){|f|f.pread(-1,0,"abc")} # Errno::EFAULT
Actions

Also available in: PDF Atom