From fbd840dfc9b563b320e11bc4465883053a0487f5 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Sun, 7 Jul 2013 22:42:43 -0600 Subject: [PATCH] PATCH: [perl #115808]: POSIX::setlocale returns bizarre value on failure It turns out that this bug is caused by a more general one, covered by [perl #118693]. But in the meantime, this commit fixes the problem for setlocale(), and makes the code slightly cleaner besides. --- ext/POSIX/POSIX.xs | 10 +++++----- lib/locale.t | 10 ++++++++++ 2 files changed, 15 insertions(+), 5 deletions(-) diff --git a/ext/POSIX/POSIX.xs b/ext/POSIX/POSIX.xs index e4c9e88..655fda3 100644 --- a/ext/POSIX/POSIX.xs +++ b/ext/POSIX/POSIX.xs @@ -1097,7 +1097,10 @@ setlocale(category, locale = 0) char * retval; CODE: retval = setlocale(category, locale); - if (retval) { + if (! retval) { + XSRETURN_UNDEF; + } + else { /* Save retval since subsequent setlocale() calls * may overwrite it. */ RETVAL = savepv(retval); @@ -1153,13 +1156,10 @@ setlocale(category, locale = 0) } #endif /* USE_LOCALE_NUMERIC */ } - else - RETVAL = NULL; OUTPUT: RETVAL CLEANUP: - if (RETVAL) - Safefree(RETVAL); + Safefree(RETVAL); NV acos(x) diff --git a/lib/locale.t b/lib/locale.t index 081783b..1126a38 100644 --- a/lib/locale.t +++ b/lib/locale.t @@ -1519,6 +1519,16 @@ if ($didwarn) { $test_num = $final_locales_test_number; +{ # perl #115808 + use warnings; + my $warned = 0; + local $SIG{__WARN__} = sub { + $warned = $_[0] =~ /uninitialized/; + }; + my $z = "y" . setlocale(&POSIX::LC_ALL, "xyzzy"); + ok($warned, "variable set to setlocale(BAD LOCALE) is considered uninitialized"); +} + # Test that tainting and case changing works on utf8 strings. These tests are # placed last to avoid disturbing the hard-coded test numbers that existed at # the time these were added above this in this file. -- 2.7.4