From: Jarkko Hietaniemi <jhi@iki.fi>
Date: Sun, 30 Dec 2001 23:12:17 +0000 (+0000)
Subject: Four wrongs can make a right.
X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2ad154feab0e255cadacb1ad90bde4145e7d573e;p=p5sagit%2Fp5-mst-13.2.git

Four wrongs can make a right.

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

diff --git a/regexec.c b/regexec.c
index 3860fd2..dfb01ed 100644
--- a/regexec.c
+++ b/regexec.c
@@ -979,8 +979,8 @@ S_find_byclass(pTHX_ regexp * prog, regnode *c, char *s, char *strend, char *sta
 		    while (s <= e) {
 			if ( utf8_to_uvchr((U8*)s, &len) == c1
 			     && (ln == len ||
-				 ibcmp_utf8(s, do_utf8, (I32)(strend - s),
-					    m, UTF, (I32)ln))
+				 !ibcmp_utf8(s, do_utf8, (I32)(strend - s),
+					     m, UTF, (I32)ln))
 			     && (norun || regtry(prog, s)) )
 			    goto got_it;
 			s += len;
@@ -1002,8 +1002,9 @@ S_find_byclass(pTHX_ regexp * prog, regnode *c, char *s, char *strend, char *sta
 			    c == (UV)UNICODE_GREEK_SMALL_LETTER_FINAL_SIGMA)
 			    c = (UV)UNICODE_GREEK_SMALL_LETTER_SIGMA;
 			if ( (c == c1 || c == c2 || f == c1 || f == c2)
-			     && ibcmp_utf8(s, do_utf8, (I32)(strend - s),
-					   m, UTF, (I32)ln)
+			     && (ln == len ||
+				 !ibcmp_utf8(s, do_utf8, (I32)(strend - s),
+					     m, UTF, (I32)ln))
 			     && (norun || regtry(prog, s)) )
 			    goto got_it;
 			s += len;
diff --git a/utf8.c b/utf8.c
index 27f86b6..0453d1b 100644
--- a/utf8.c
+++ b/utf8.c
@@ -1668,7 +1668,7 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, bool u1, register I32 len1, const char *s2
 {
      register U8 *a  = (U8*)s1;
      register U8 *b  = (U8*)s2;
-     register U8 *ae = b + len1;
+     register U8 *ae = a + len1;
      register U8 *be = b + len2;
      STRLEN la, lb;
      UV ca, cb;
@@ -1703,7 +1703,8 @@ Perl_ibcmp_utf8(pTHX_ const char *s1, bool u1, register I32 len1, const char *s2
 	       else
 		    ulen2 = 1;
 	       if (ulen1 != ulen2
-		   || (ulen1 == 1 && PL_fold[ca] != PL_fold[cb])
+		   || (ca < 256 && cb < 256 &&
+		       PL_fold[ca] != PL_fold[cb])
 		   || memNE((char *)tmpbuf1, (char *)tmpbuf2, ulen1))
 		    return 1; /* mismatch */
 	  }