diff options
author | Karl Williamson <khw@cpan.org> | 2014-11-18 21:45:46 -0700 |
---|---|---|
committer | Karl Williamson <khw@cpan.org> | 2014-11-19 09:38:47 -0700 |
commit | eb9d0228c41a1528b2864e335094c0c25258789a (patch) | |
tree | a658846600e100dca7ddad44bc8cc719354146ec /locale.c | |
parent | 96d11ca8c0301ed6fd2f23dec68c455ef2787aa7 (diff) | |
download | perl-eb9d0228c41a1528b2864e335094c0c25258789a.tar.gz |
locale.c: Account for setlocale using static storage
Some systems setlocale()s use static storage for the locale name
returned by it, so that a subsequent setlocale overwrites it.
Therefore, you must make a copy of the name if you want it to work after
the next setlocale.
Thanks to Craig Berry for finding and diagnosing this problem.
Diffstat (limited to 'locale.c')
-rw-r--r-- | locale.c | 11 |
1 files changed, 9 insertions, 2 deletions
@@ -351,10 +351,17 @@ Perl_new_ctype(pTHX_ const char *newctype) #endif if (bad_count || multi_byte_locale) { + + /* We have to save 'newctype' because the setlocale() just below + * may destroy it. The next setlocale() further down should + * restore it properly so that the intermediate change here is + * transparent to this function's caller */ + const char * const badlocale = savepv(newctype); + setlocale(LC_CTYPE, "C"); Perl_warner(aTHX_ packWARN(WARN_LOCALE), "Locale '%s' may not work well.%s%s%s\n", - newctype, + badlocale, (multi_byte_locale) ? " Some characters in it are not recognized by" " Perl." @@ -368,7 +375,7 @@ Perl_new_ctype(pTHX_ const char *newctype) ? bad_chars_list : "" ); - setlocale(LC_CTYPE, newctype); + setlocale(LC_CTYPE, badlocale); } } |