Skip to content

Commit a25786b

Browse files
committed
locale.c: Don't do asymmetric back out on failure
This fixes #23519 When something goes wrong doing locale-aware string collation, the code attempts to carry on as well as can be expected. Prior to this commit the backout code was asymmetric, trying to undo things that had not been done. This happened when the failure was early on. In the case of this ticket, the platform has a defective locale that was detectable before getting very far along. The solution adopted here is to jump to a different label for those early failures that does less backout than for later failures.
1 parent 7c4efc4 commit a25786b

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

locale.c

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9663,7 +9663,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
96639663
if (PL_collxfrm_base != 0) { /* bad collation => skip */
96649664
DEBUG_L(PerlIO_printf(Perl_debug_log,
96659665
"mem_collxfrm_: locale's collation is defective\n"));
9666-
goto bad;
9666+
goto bad_no_strxfrm;
96679667
}
96689668

96699669
/* (mult, base) == (0,0) means we need to calculate mult and base
@@ -9789,7 +9789,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
97899789
DEBUG_L(PerlIO_printf(Perl_debug_log,
97909790
"mem_collxfrm_: Couldn't find any character to replace"
97919791
" embedded NULs in locale %s with", PL_collation_name));
9792-
goto bad;
9792+
goto bad_no_strxfrm;
97939793
}
97949794

97959795
DEBUG_L(PerlIO_printf(Perl_debug_log,
@@ -9930,7 +9930,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
99309930
"mem_collxfrm_: Couldn't find any character to"
99319931
" replace above-Latin1 chars in locale %s with",
99329932
PL_collation_name));
9933-
goto bad;
9933+
goto bad_no_strxfrm;
99349934
}
99359935

99369936
DEBUG_L(PerlIO_printf(Perl_debug_log,
@@ -10090,7 +10090,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
1009010090
if (UNLIKELY(! xbuf)) {
1009110091
DEBUG_L(PerlIO_printf(Perl_debug_log,
1009210092
"mem_collxfrm_: Couldn't malloc %zu bytes\n", xAlloc));
10093-
goto bad;
10093+
goto bad_no_strxfrm;
1009410094
}
1009510095

1009610096
/* Store the collation id */
@@ -10286,6 +10286,9 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
1028610286
DEBUG_L(print_collxfrm_input_and_return(s, s + len, NULL, 0, utf8));
1028710287
CLEANUP_STRXFRM;
1028810288

10289+
bad_no_strxfrm: /* Found a problem before strxfrm() got called */
10290+
DEBUG_L(print_collxfrm_input_and_return(s, s + len, NULL, 0, utf8));
10291+
1028910292
Safefree(xbuf);
1029010293
*xlen = 0;
1029110294

0 commit comments

Comments
 (0)