From 56f8964d87ef7abe7c60374712426df2bb1e0340 Mon Sep 17 00:00:00 2001 From: Karl Williamson Date: Thu, 23 Nov 2023 05:05:42 -0700 Subject: [PATCH] locale_threads.t: Better handle weird locales The previous code was generating bunches of uninitialized variable warnings, due to 1) not checking for definedness early; 2) the loop termination needs to be reevaluated each time because there is a potential splice, shortening the array. This only happens, I believe, on MingW not using UCRT. --- lib/locale_threads.t | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/lib/locale_threads.t b/lib/locale_threads.t index a0249f0df383..01649d9c6619 100644 --- a/lib/locale_threads.t +++ b/lib/locale_threads.t @@ -845,18 +845,16 @@ SKIP: { # and then a setlocale of the resulting one. Discard locales which have # any unacceptable name if (${^O} eq "MSWin32" && $Config{'libc'} !~ /ucrt/) { - for my $i (0 .. $#locales) { - my $locale_name = $locales[$i]->{locale_name}; + @locales = grep { + my $locale_name = $_->{locale_name}; my $underlying_name = setlocale(&LC_CTYPE, $locale_name); # Defeat any attempt to skip the setlocale if the same as current, # by switching to a locale very unlikey to be the current one. setlocale($LC_ALL, "Albanian"); - next if setlocale(&LC_CTYPE, $underlying_name); - - splice @locales, $i, 1; - } + defined($underlying_name) && setlocale(&LC_CTYPE, $underlying_name) + } @locales; } # Create a hash of the errnos: