This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Simplify expression
authorKarl Williamson <khw@cpan.org>
Fri, 5 Jan 2018 19:57:37 +0000 (12:57 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 31 Jan 2018 05:49:02 +0000 (22:49 -0700)
Since this is operating on C strings, we don't have to check the
lengths, but can rely on the underlying functions to work.

locale.c

index 66ef3b3..b3e1b0e 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -3219,10 +3219,13 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
                     Safefree(save_ctype_locale);
                 }
 
-                is_utf8 = (   (   strlen(codeset) == STRLENs("UTF-8")
-                               && foldEQ(codeset, STR_WITH_LEN("UTF-8")))
-                           || (   strlen(codeset) == STRLENs("UTF8")
-                               && foldEQ(codeset, STR_WITH_LEN("UTF8"))));
+                              /* If the implementation of foldEQ() somehow were
+                               * to change to not go byte-by-byte, this could
+                               * read past end of string, as only one length is
+                               * checked.  But currently, a premature NUL will
+                               * compare false, and it will stop there */
+                is_utf8 = cBOOL(   foldEQ(codeset, STR_WITH_LEN("UTF-8"))
+                                || foldEQ(codeset, STR_WITH_LEN("UTF8")));
 
                 DEBUG_L(PerlIO_printf(Perl_debug_log,
                        "\tnllanginfo returned CODESET '%s'; ?UTF8 locale=%d\n",