From: Tony Cook Date: Fri, 16 Mar 2012 14:10:36 +0000 (+1100) Subject: fix a fencepost error I found trying to fall asleep X-Git-Tag: upstream/5.20.0~4576^2~4 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=90f6536b6e4fefdbe12a64f4201c9f73580aab88;p=platform%2Fupstream%2Fperl.git fix a fencepost error I found trying to fall asleep --- 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