This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Use only C89 legal C
authorKarl Williamson <khw@cpan.org>
Tue, 7 Feb 2017 17:00:19 +0000 (10:00 -0700)
committerKarl Williamson <khw@cpan.org>
Wed, 8 Feb 2017 14:47:52 +0000 (07:47 -0700)
An array was being declared and initialized from a non-constant.

Spotted by James Keenan

locale.c

index 5c1c552..01962ea 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -1505,10 +1505,10 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
                     char * x;       /* j's xfrm plus collation index */
                     STRLEN x_len;   /* length of 'x' */
                     STRLEN trial_len = 1;
+                    char cur_source[] = { '\0', '\0' };
 
-                    /* Create a 1 byte string of the current code point */
-                    char cur_source[] = { (char) j, '\0' };
-
+                    /* Skip non-controls the first time through the loop.  The
+                     * controls in a UTF-8 locale are the L1 ones */
                     if (! try_non_controls && (PL_in_utf8_COLLATE_locale)
                                                ? ! isCNTRL_L1(j)
                                                : ! isCNTRL_LC(j))
@@ -1516,6 +1516,9 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
                         continue;
                     }
 
+                    /* Create a 1-char string of the current code point */
+                    cur_source[0] = (char) j;
+
                     /* Then transform it */
                     x = _mem_collxfrm(cur_source, trial_len, &x_len,
                                       0 /* The string is not in UTF-8 */);
@@ -1671,9 +1674,10 @@ Perl__mem_collxfrm(pTHX_ const char *input_string,
                     for (j = 1; j < 256; j++) {
                         char * x;
                         STRLEN x_len;
+                        char cur_source[] = { '\0', '\0' };
 
-                        /* Create a 1-char string of the current code point. */
-                        char cur_source[] = { (char) j, '\0' };
+                        /* Create a 1-char string of the current code point */
+                        cur_source[0] = (char) j;
 
                         /* Then transform it */
                         x = _mem_collxfrm(cur_source, 1, &x_len, FALSE);