Skip to content

Commit b9e1bad

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 cc9354b commit b9e1bad

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
@@ -9653,7 +9653,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
96539653
if (PL_collxfrm_base != 0) { /* bad collation => skip */
96549654
DEBUG_L(PerlIO_printf(Perl_debug_log,
96559655
"mem_collxfrm_: locale's collation is defective\n"));
9656-
goto bad;
9656+
goto bad_no_strxfrm;
96579657
}
96589658

96599659
/* (mult, base) == (0,0) means we need to calculate mult and base
@@ -9779,7 +9779,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
97799779
DEBUG_L(PerlIO_printf(Perl_debug_log,
97809780
"mem_collxfrm_: Couldn't find any character to replace"
97819781
" embedded NULs in locale %s with", PL_collation_name));
9782-
goto bad;
9782+
goto bad_no_strxfrm;
97839783
}
97849784

97859785
DEBUG_L(PerlIO_printf(Perl_debug_log,
@@ -9920,7 +9920,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
99209920
"mem_collxfrm_: Couldn't find any character to"
99219921
" replace above-Latin1 chars in locale %s with",
99229922
PL_collation_name));
9923-
goto bad;
9923+
goto bad_no_strxfrm;
99249924
}
99259925

99269926
DEBUG_L(PerlIO_printf(Perl_debug_log,
@@ -10080,7 +10080,7 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
1008010080
if (UNLIKELY(! xbuf)) {
1008110081
DEBUG_L(PerlIO_printf(Perl_debug_log,
1008210082
"mem_collxfrm_: Couldn't malloc %zu bytes\n", xAlloc));
10083-
goto bad;
10083+
goto bad_no_strxfrm;
1008410084
}
1008510085

1008610086
/* Store the collation id */
@@ -10276,6 +10276,9 @@ Perl_mem_collxfrm_(pTHX_ const char *input_string,
1027610276
DEBUG_L(print_collxfrm_input_and_return(s, s + len, NULL, 0, utf8));
1027710277
CLEANUP_STRXFRM;
1027810278

10279+
bad_no_strxfrm: /* Found a problem before strxfrm() got called */
10280+
DEBUG_L(print_collxfrm_input_and_return(s, s + len, NULL, 0, utf8));
10281+
1027910282
Safefree(xbuf);
1028010283
*xlen = 0;
1028110284

0 commit comments

Comments
 (0)