From: Dave Mitchell <davem@fdisolutions.com>
Date: Fri, 30 May 2008 21:41:05 +0000 (+0000)
Subject: [perl #53746] bug with index() matching beyond end of string
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=8ba22ff48d546c5622ef74aee96415810fcbf7a0;p=p5sagit%2Fp5-mst-13.2.git

[perl #53746] bug with index() matching beyond end of string
An off-by-one error meant that index($str,...)
was effectively being executed as index("$str\0", ...).
Probably introduced by change #26511.
p4raw-link: @26511 on //depot/perl: 4c8626beeba549aaf3f327729c56a599716ee8b7

p4raw-id: //depot/perl@33952
---

diff --git a/t/op/index.t b/t/op/index.t
index 896cd12..834814e 100755
--- a/t/op/index.t
+++ b/t/op/index.t
@@ -181,7 +181,6 @@ SKIP: {
             my $res = $$test [$l];
 
             {
-                local $::TODO = ($l == 3 && $i == 7 ? "Bug #53746" : "");
                 is (index ($str, $q), $res, "Find NUL character(s)");
             }
 
diff --git a/util.c b/util.c
index a6b5c1c..b59959c 100644
--- a/util.c
+++ b/util.c
@@ -440,9 +440,9 @@ Perl_ninstr(pTHX_ const char *big, const char *bigend, const char *little, const
     if (little >= lend)
         return (char*)big;
     {
-        const char first = *little++;
+        const char first = *little;
         const char *s, *x;
-        bigend -= lend - little;
+        bigend -= lend - little++;
     OUTER:
         while (big <= bigend) {
             if (*big++ == first) {