From a5a291f55baf01a6b4b1013e2d3c722a0ad77432 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 31 Oct 2010 12:36:49 -0600 Subject: reginclass: Make explicit the length assumptions 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 | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) (limited to 'regexec.c') diff --git a/regexec.c b/regexec.c index f6f743584f..5192899aa2 100644 --- 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)"); } + 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) { - maxlen = *lenp; - *lenp = UNISKIP(NATIVE_TO_UNI(c)); + maxlen = (*lenp > c_len) ? *lenp : c_len; + *lenp = c_len; } else { - maxlen = UNISKIP(NATIVE_TO_UNI(c)); + maxlen = c_len; } if (utf8_target || (flags & ANYOF_UNICODE)) { -- cgit v1.2.1