Project

General

Profile

Actions

Bug #19252

closed

IO::Buffer.pread last argument is always ignored?

Added by zverok (Victor Shepelev) over 1 year ago. Updated over 1 year ago.

Status:
Closed
Target version:
-
[ruby-core:111386]

Description

I am trying to document new IO::Buffer#pread and #pwrite methods.

According to what I can guess from code and tests, this code:

IO::Buffer.for('teststring') do |buffer| 
  buffer.pread(File.open('/dev/urandom', 'rb'), 0, 2, 3)
  p buffer.get_string 
end

...is expected to read 2 chars from /dev/urandom, starting from 0th char, and write it to buffer starting from its 3rd byte.
Actual output:

"F\x94ststring"

E.g. two first chars of the buffer are replaced.

Am I missing something, or is it a legitimate bug?..

UPD: Seems the same for pwrite:

IO::Buffer.for('1234567').pwrite(File.open('tmp/buf.txt', 'wb'), 0, 2, 3) # expected to write "45" to file
`cat tmp/buf.txt`
# => "12"

Updated by ioquatix (Samuel Williams) over 1 year ago

It looks like the base pointer is not computed correctly, let me check and fix it.

Updated by ioquatix (Samuel Williams) over 1 year ago

  • Status changed from Open to Closed

Merged.

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0