From: Karl Williamson Date: Mon, 8 Jul 2013 04:42:43 +0000 (-0600) Subject: PATCH: [perl #115808]: POSIX::setlocale returns bizarre value on failure X-Git-Tag: upstream/5.20.0~2776 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=fbd840dfc9b563b320e11bc4465883053a0487f5;p=platform%2Fupstream%2Fperl.git 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. --- 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.