Skip to content

Commit 2e770cd

Browse files
authored
Fix argument handling in IO::Buffer#each_byte (ruby#15309)
The method incorrectly ignored its first argument and treated the second argument as offset and the third as count. This change makes the first argument be treated as offset and the second as count. Also fix incorrect block parameter in comments.
1 parent a60cd87 commit 2e770cd

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

io_buffer.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2231,7 +2231,7 @@ io_buffer_values(int argc, VALUE *argv, VALUE self)
22312231

22322232
/*
22332233
* call-seq:
2234-
* each_byte([offset, [count]]) {|offset, byte| ...} -> self
2234+
* each_byte([offset, [count]]) {|byte| ...} -> self
22352235
* each_byte([offset, [count]]) -> enumerator
22362236
*
22372237
* Iterates over the buffer, yielding each byte starting from +offset+.
@@ -2255,7 +2255,7 @@ io_buffer_each_byte(int argc, VALUE *argv, VALUE self)
22552255
rb_io_buffer_get_bytes_for_reading(self, &base, &size);
22562256

22572257
size_t offset, count;
2258-
io_buffer_extract_offset_count(RB_IO_BUFFER_DATA_TYPE_U8, size, argc-1, argv+1, &offset, &count);
2258+
io_buffer_extract_offset_count(RB_IO_BUFFER_DATA_TYPE_U8, size, argc, argv, &offset, &count);
22592259

22602260
for (size_t i = 0; i < count; i++) {
22612261
unsigned char *value = (unsigned char *)base + i + offset;

test/ruby/test_io_buffer.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -473,6 +473,7 @@ def test_each_byte
473473
buffer = IO::Buffer.for(string)
474474

475475
assert_equal string.bytes, buffer.each_byte.to_a
476+
assert_equal string.bytes[3, 5], buffer.each_byte(3, 5).to_a
476477
end
477478

478479
def test_zero_length_each_byte

0 commit comments

Comments
 (0)