This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
locale.c: Compare apples to apples
authorKarl Williamson <public@khwilliamson.com>
Thu, 27 Jun 2013 20:25:43 +0000 (14:25 -0600)
committerKarl Williamson <public@khwilliamson.com>
Sat, 6 Jul 2013 04:29:59 +0000 (22:29 -0600)
Prior to this patch, one parameter to strNE would have been through a
standardizing function, while the other had not.  By standardizing both
before doing the compare, we avoid false positives.

locale.c

index bb0baf5..a73a864 100644 (file)
--- a/locale.c
+++ b/locale.c
@@ -111,6 +111,7 @@ void
 Perl_new_numeric(pTHX_ const char *newnum)
 {
 #ifdef USE_LOCALE_NUMERIC
+    char *save_newnum;
     dVAR;
 
     if (! newnum) {
@@ -121,14 +122,18 @@ Perl_new_numeric(pTHX_ const char *newnum)
        return;
     }
 
-    if (! PL_numeric_name || strNE(PL_numeric_name, newnum)) {
+    save_newnum = stdize_locale(savepv(newnum));
+    if (! PL_numeric_name || strNE(PL_numeric_name, save_newnum)) {
        Safefree(PL_numeric_name);
-       PL_numeric_name = stdize_locale(savepv(newnum));
-       PL_numeric_standard = ((*newnum == 'C' && newnum[1] == '\0')
-                              || strEQ(newnum, "POSIX"));
+       PL_numeric_name = save_newnum;
+       PL_numeric_standard = ((*save_newnum == 'C' && save_newnum[1] == '\0')
+                              || strEQ(save_newnum, "POSIX"));
        PL_numeric_local = TRUE;
        set_numeric_radix();
     }
+    else {
+        Safefree(save_newnum);
+    }
 
 #endif /* USE_LOCALE_NUMERIC */
 }