S_tokeq()'s fast scan loop should terminate on \\ not \
authorNicholas Clark <nick@ccl4.org>
Fri, 22 Oct 2010 06:41:39 +0000 (07:41 +0100)
committerNicholas Clark <nick@ccl4.org>
Fri, 22 Oct 2010 06:41:39 +0000 (07:41 +0100)
As-was, it would drop out of the scanner into the backslashed-backslash
processing loop earlier than need be, and hence would be copying the octets
of strings (in place) as soon as any backslash had been seen. Now it defers
copying until copying is actually unavoidable.

toke.c

diff --git a/toke.c b/toke.c
index 731c2b4..b6f9cc9 100644 (file)
--- a/toke.c
+++ b/toke.c
@@ -2253,7 +2253,8 @@ S_tokeq(pTHX_ SV *sv)
     if (SvTYPE(sv) >= SVt_PVIV && SvIVX(sv) == -1)
        goto finish;
     send = s + len;
-    while (s < send && *s != '\\')
+    /* This is relying on the SV being "well formed" with a trailing '\0'  */
+    while (s < send && !(*s == '\\' && s[1] == '\\'))
        s++;
     if (s == send)
        goto finish;