Fix broken locale case-insensitive matching
authorKarl Williamson <public@khwilliamson.com>
Sat, 30 Nov 2013 22:26:07 +0000 (15:26 -0700)
committerKarl Williamson <public@khwilliamson.com>
Tue, 3 Dec 2013 17:05:23 +0000 (10:05 -0700)
Commit 68067e4e501e2ae1c0fb44558b6aa5c0a80a4143 inadvertently
broke regular expression /i matching under locale.  The tests for this
were defective, so the breakage was not caught.  A later commit will fix
the tests, but this commit restores the functionality.

It also casts the input parameter to some functions to be U8 to make
sure that optimizing compilers can omit bounds checks

locale.c

index 6284199..31aa592 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -190,11 +190,11 @@ Perl_new_ctype(pTHX_ const char *newctype)
 
     PERL_ARGS_ASSERT_NEW_CTYPE;
 
-    for (i = 0; i ; i++) {
-       if (isUPPER_LC(i))
-           PL_fold_locale[i] = toLOWER_LC(i);
-       else if (isLOWER_LC(i))
-           PL_fold_locale[i] = toUPPER_LC(i);
+    for (i = 0; i < 256; i++) {
+       if (isUPPER_LC((U8) i))
+           PL_fold_locale[i] = toLOWER_LC((U8) i);
+       else if (isLOWER_LC((U8) i))
+           PL_fold_locale[i] = toUPPER_LC((U8) i);
        else
            PL_fold_locale[i] = i;
     }