summaryrefslogtreecommitdiff
path: root/locale.c
diff options
context:
space:
mode:
authorKarl Williamson <khw@cpan.org>2014-07-11 15:54:38 -0600
committerKarl Williamson <khw@cpan.org>2014-07-12 08:41:14 -0600
commit4f72bb37d82e7b97d8480ac800e3937d38084e18 (patch)
tree3079a5ba58c49753600097a903dfbf517d706d4f /locale.c
parent0080c90acf59b31e586bcf1d964eaf3d4220e8a5 (diff)
downloadperl-4f72bb37d82e7b97d8480ac800e3937d38084e18.tar.gz
locale.c: Use safer code practice
The interior-most function can return NULL. Currently savepv() which is the next outer function handles this correctly, as does the next outer function, but it is dangerous to rely on that behavior. So we test for NULL before calling functions on a NULL ptr.
Diffstat (limited to 'locale.c')
-rw-r--r--locale.c11
1 files changed, 6 insertions, 5 deletions
diff --git a/locale.c b/locale.c
index ca138da53f..1e67e57ea0 100644
--- a/locale.c
+++ b/locale.c
@@ -1048,12 +1048,13 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
if (category != LC_CTYPE) { /* These work only on LC_CTYPE */
/* Get the current LC_CTYPE locale */
- save_ctype_locale = stdize_locale(savepv(setlocale(LC_CTYPE, NULL)));
+ save_ctype_locale = setlocale(LC_CTYPE, NULL);
if (! save_ctype_locale) {
DEBUG_L(PerlIO_printf(Perl_debug_log,
"Could not find current locale for LC_CTYPE\n"));
goto cant_use_nllanginfo;
}
+ save_ctype_locale = stdize_locale(savepv(save_ctype_locale));
/* If LC_CTYPE and the desired category use the same locale, this
* means that finding the value for LC_CTYPE is the same as finding
@@ -1081,8 +1082,9 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
# if defined(HAS_NL_LANGINFO) && defined(CODESET)
{
- char *codeset = savepv(nl_langinfo(CODESET));
+ char *codeset = nl_langinfo(CODESET);
if (codeset && strNE(codeset, "")) {
+ codeset = savepv(codeset);
/* If we switched LC_CTYPE, switch back */
if (save_ctype_locale) {
@@ -1100,7 +1102,6 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
Safefree(save_input_locale);
return is_utf8;
}
- Safefree(codeset);
}
# endif
@@ -1181,13 +1182,13 @@ Perl__is_cur_LC_category_utf8(pTHX_ int category)
if (category != LC_MONETARY) {
- save_monetary_locale = stdize_locale(savepv(setlocale(LC_MONETARY,
- NULL)));
+ save_monetary_locale = setlocale(LC_MONETARY, NULL);
if (! save_monetary_locale) {
DEBUG_L(PerlIO_printf(Perl_debug_log,
"Could not find current locale for LC_MONETARY\n"));
goto cant_use_monetary;
}
+ save_monetary_locale = stdize_locale(savepv(save_monetary_locale));
if (strNE(save_monetary_locale, save_input_locale)) {
if (! setlocale(LC_MONETARY, save_input_locale)) {