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.
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);
}
#endif /* USE_LOCALE_NUMERIC */
}
- else
- RETVAL = NULL;
OUTPUT:
RETVAL
CLEANUP:
- if (RETVAL)
- Safefree(RETVAL);
+ Safefree(RETVAL);
NV
acos(x)
$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.