This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
reginclass: Make explicit the length assumptions
authorKarl Williamson <public@khwilliamson.com>
Sun, 31 Oct 2010 18:36:49 +0000 (12:36 -0600)
committerFather Chrysostomos <sprout@cpan.org>
Sun, 31 Oct 2010 23:10:54 +0000 (16:10 -0700)
reginclass assumes that can match always at least one character.  Make
that explicit, and now that we have that length always saved, don't
recalculate it.

regexec.c

index f6f7435..5192899 100644 (file)
--- a/regexec.c
+++ b/regexec.c
@@ -6220,18 +6220,20 @@ S_reginclass(pTHX_ const regexp * const prog, register const regnode * const n,
        if (c_len == (STRLEN)-1)
            Perl_croak(aTHX_ "Malformed UTF-8 character (fatal)");
     }
        if (c_len == (STRLEN)-1)
            Perl_croak(aTHX_ "Malformed UTF-8 character (fatal)");
     }
+    else {
+       c_len = 1;
+    }
 
 
-    /* Use passed in max length, or one character if none passed in.  And
-     * assume will match just one character.  This is overwritten later if
-     * matched more.  (Note that the code makes an implicit assumption that any
-     * passed in max is at least one character) */
+    /* Use passed in max length, or one character if none passed in or less
+     * than one character.  And assume will match just one character.  This is
+     * overwritten later if matched more. */
     if (lenp) {
     if (lenp) {
-       maxlen = *lenp;
-       *lenp = UNISKIP(NATIVE_TO_UNI(c));
+       maxlen = (*lenp > c_len) ? *lenp : c_len;
+       *lenp = c_len;
 
     }
     else {
 
     }
     else {
-       maxlen = UNISKIP(NATIVE_TO_UNI(c));
+       maxlen = c_len;
     }
 
     if (utf8_target || (flags & ANYOF_UNICODE)) {
     }
 
     if (utf8_target || (flags & ANYOF_UNICODE)) {