From 7e134cf71e2535b562cd2d81e3ff69cbe49d0ce0 Mon Sep 17 00:00:00 2001 From: shirosaki Date: Tue, 8 May 2012 12:01:05 +0000 Subject: * io.c (io_unread): fix IO#pos with mode 'r' bug on Windows. If the end of reading buffer is CR, io_unread() needs to unread one more byte. [ruby-core:44874] [Bug #6401] * test/ruby/test_io_m17n.rb (TestIO_M17N#test_pos_with_buffer_end_cr): add a test for above. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35594 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- io.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'io.c') diff --git a/io.c b/io.c index c4b7f128e0..5997c29611 100644 --- a/io.c +++ b/io.c @@ -457,6 +457,12 @@ io_unread(rb_io_t *fptr) /* add extra offset for removed '\r' in rbuf */ extra_max = (long)(pos - fptr->rbuf.len); p = fptr->rbuf.ptr + fptr->rbuf.off; + + /* if the end of rbuf is '\r', rbuf doesn't have '\r' within rbuf.len */ + if (*(fptr->rbuf.ptr + fptr->rbuf.capa - 1) == '\r') { + newlines++; + } + for (i = 0; i < fptr->rbuf.len; i++) { if (*p == '\n') newlines++; if (extra_max == newlines) break; -- cgit v1.2.3