fix a fencepost error I found trying to fall asleep
authorTony Cook <tony@develop-help.com>
Fri, 16 Mar 2012 14:10:36 +0000 (01:10 +1100)
committerTony Cook <tony@develop-help.com>
Sat, 8 Dec 2012 22:32:44 +0000 (09:32 +1100)
sv.c
t/io/utf8.t

diff --git a/sv.c b/sv.c
index 78eeddd..e2bed05 100644 (file)
--- 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;
 
index ed535a3..919b734 100644 (file)
@@ -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 .= <F>;
     is($line, "foo\xE4bar\xFE", "rcatline with \$/ = \\4");
+    $line = <F>;
+    is($line, "a\xE4a", "readline with boundary condition");
     close F;
 
     # badly encoded at EOF