summaryrefslogtreecommitdiff
path: root/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'io.c')
-rw-r--r--io.c6
1 files changed, 6 insertions, 0 deletions
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;