From 90f6536b6e4fefdbe12a64f4201c9f73580aab88 Mon Sep 17 00:00:00 2001 From: Tony Cook Date: Sat, 17 Mar 2012 01:10:36 +1100 Subject: [PATCH] fix a fencepost error I found trying to fall asleep --- sv.c | 5 +++-- t/io/utf8.t | 5 ++++- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/sv.c b/sv.c index 78eeddd..e2bed05 100644 --- a/sv.c +++ b/sv.c @@ -7719,10 +7719,11 @@ S_sv_gets_read_record(pTHX_ SV *const sv, PerlIO *const fp, I32 append) } } - if (!charstart) { + if (charcount < recsize) { /* read the rest of the current character, and maybe the beginning of the next, if we need it */ - STRLEN readsize = skip - (bend - bufp) + (charcount + 1 < recsize); + STRLEN readsize = (charstart ? 0 : skip - (bend - bufp)) + + (charcount + 1 < recsize); STRLEN bufp_offset = bufp - buffer; SSize_t morebytesread; diff --git a/t/io/utf8.t b/t/io/utf8.t index ed535a3..919b734 100644 --- a/t/io/utf8.t +++ b/t/io/utf8.t @@ -10,7 +10,7 @@ BEGIN { no utf8; # needed for use utf8 not griping about the raw octets -plan(tests => 58); +plan(tests => 59); $| = 1; @@ -354,6 +354,7 @@ is($failed, undef); open F, ">:utf8", $a_file; print F "foo\xE4"; print F "bar\xFE"; + print F "a\xE4a"; close F; open F, "<:utf8", $a_file; local $/ = \4; @@ -361,6 +362,8 @@ is($failed, undef); is($line, "foo\xE4", "readline with \$/ = \\4"); $line .= ; is($line, "foo\xE4bar\xFE", "rcatline with \$/ = \\4"); + $line = ; + is($line, "a\xE4a", "readline with boundary condition"); close F; # badly encoded at EOF -- 2.7.4