summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ChangeLog5
-rw-r--r--io.c9
-rw-r--r--test/ruby/test_io.rb10
3 files changed, 18 insertions, 6 deletions
diff --git a/ChangeLog b/ChangeLog
index c4aa64f0fb..50c7e63b47 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,8 @@
+Sat Jul 30 23:14:44 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
+
+ * io.c (rb_io_each_byte): rbuf can be refreshed during yield.
+ [Bug #5119]
+
Sat Jul 30 22:35:50 2011 Naohisa Goto <ngotogenome@gmail.com>
* strftime.c (NEEDS): avoid SEGV due to integer overflow in
diff --git a/io.c b/io.c
index 5307ad4d3f..ddb6d9576a 100644
--- a/io.c
+++ b/io.c
@@ -2829,13 +2829,10 @@ rb_io_each_byte(VALUE io)
GetOpenFile(io, fptr);
for (;;) {
- p = fptr->rbuf.ptr+fptr->rbuf.off;
- e = p + fptr->rbuf.len;
- while (p < e) {
- fptr->rbuf.off++;
- fptr->rbuf.len--;
+ while (fptr->rbuf.len > 0) {
+ p = fptr->rbuf.ptr + fptr->rbuf.off++;
+ e = p + fptr->rbuf.len--;
rb_yield(INT2FIX(*p & 0xff));
- p++;
errno = 0;
}
rb_io_check_byte_readable(fptr);
diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb
index 0325867496..4276157a20 100644
--- a/test/ruby/test_io.rb
+++ b/test/ruby/test_io.rb
@@ -235,6 +235,16 @@ class TestIO < Test::Unit::TestCase
end)
end
+ def test_each_byte_with_seek
+ t = make_tempfile
+ bug5119 = '[ruby-core:38609]'
+ i = 0
+ open(t.path) do |f|
+ f.each_byte {i = f.pos}
+ end
+ assert_equal(12, i, bug5119)
+ end
+
def test_each_codepoint
t = make_tempfile
bug2959 = '[ruby-core:28650]'