Skip to content

Commit e4d3d0c

Browse files
committed
doop.c: Remove dead code
As the comments say, as of 5.32 we disallowed doing bitwise vector operations on strings that contain code points that can't be converted to bytes (i.e. above 0xFF). Yet the code to do just that was left in, but was intercepted by a croak before it got that far. This removes that, and its calculations.
1 parent 83c2748 commit e4d3d0c

File tree

1 file changed

+11
-46
lines changed

1 file changed

+11
-46
lines changed

doop.c

Lines changed: 11 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,12 +1008,6 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
10081008
bool result_needs_to_be_utf8 = FALSE;
10091009
bool left_utf8 = FALSE;
10101010
bool right_utf8 = FALSE;
1011-
U8 * left_non_downgraded = NULL;
1012-
U8 * right_non_downgraded = NULL;
1013-
Size_t left_non_downgraded_len = 0;
1014-
Size_t right_non_downgraded_len = 0;
1015-
char * non_downgraded = NULL;
1016-
Size_t non_downgraded_len = 0;
10171011

10181012
PERL_ARGS_ASSERT_DO_VOP;
10191013

@@ -1031,34 +1025,25 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
10311025
/* This needs to come after SvPV to ensure that string overloading has
10321026
fired off. */
10331027

1034-
/* Create downgraded temporaries of any UTF-8 encoded operands */
1028+
/* Create downgraded temporaries of any UTF-8 encoded operands. As of
1029+
* perl-5.32, we no longer accept above-FF code points at all */
10351030
if (DO_UTF8(left)) {
1036-
const U8 * save_lc = (U8 *) lc;
1037-
10381031
left_utf8 = TRUE;
10391032
result_needs_to_be_utf8 = TRUE;
10401033

1041-
left_non_downgraded_len = leftlen;
1042-
lc = (char *) bytes_from_utf8_loc((const U8 *) lc, &leftlen,
1043-
&left_utf8,
1044-
(const U8 **) &left_non_downgraded);
1045-
/* Calculate the number of trailing unconvertible bytes. This quantity
1046-
* is the original length minus the length of the converted portion. */
1047-
left_non_downgraded_len -= left_non_downgraded - save_lc;
1048-
SAVEFREEPV(lc);
1034+
lc = (char *) bytes_from_utf8((const U8 *) lc, &leftlen, &left_utf8);
1035+
if (! left_utf8) {
1036+
SAVEFREEPV(lc);
1037+
}
10491038
}
10501039
if (DO_UTF8(right)) {
1051-
const U8 * save_rc = (U8 *) rc;
1052-
10531040
right_utf8 = TRUE;
10541041
result_needs_to_be_utf8 = TRUE;
10551042

1056-
right_non_downgraded_len = rightlen;
1057-
rc = (char *) bytes_from_utf8_loc((const U8 *) rc, &rightlen,
1058-
&right_utf8,
1059-
(const U8 **) &right_non_downgraded);
1060-
right_non_downgraded_len -= right_non_downgraded - save_rc;
1061-
SAVEFREEPV(rc);
1043+
rc = (char *) bytes_from_utf8((const U8 *) rc, &rightlen, &right_utf8);
1044+
if (! right_utf8) {
1045+
SAVEFREEPV(rc);
1046+
}
10621047
}
10631048

10641049
/* We set 'len' to the length that the operation actually operates on. The
@@ -1069,9 +1054,7 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
10691054
* on zeros without having to do it. In the case of '&', the result is
10701055
* zero, and the dangling portion is simply discarded. For '|' and '^', the
10711056
* result is the same as the other operand, so the dangling part is just
1072-
* appended to the final result, unchanged. As of perl-5.32, we no longer
1073-
* accept above-FF code points in the dangling portion.
1074-
*/
1057+
* appended to the final result, unchanged. */
10751058
if (left_utf8 || right_utf8) {
10761059
Perl_croak(aTHX_ FATAL_ABOVE_FF_MSG, PL_op_desc[optype]);
10771060
}
@@ -1173,29 +1156,11 @@ Perl_do_vop(pTHX_ I32 optype, SV *sv, SV *left, SV *right)
11731156
sv_catpvn_nomg(sv, lsave + len, leftlen - len);
11741157
}
11751158
*SvEND(sv) = '\0';
1176-
1177-
/* If there is trailing stuff that couldn't be converted from UTF-8, it
1178-
* is appended as-is for the ^ and | operators. This preserves
1179-
* backwards compatibility */
1180-
if (right_non_downgraded) {
1181-
non_downgraded = (char *) right_non_downgraded;
1182-
non_downgraded_len = right_non_downgraded_len;
1183-
}
1184-
else if (left_non_downgraded) {
1185-
non_downgraded = (char *) left_non_downgraded;
1186-
non_downgraded_len = left_non_downgraded_len;
1187-
}
1188-
11891159
break;
11901160
}
11911161

11921162
if (result_needs_to_be_utf8) {
11931163
sv_utf8_upgrade_nomg(sv);
1194-
1195-
/* Append any trailing UTF-8 as-is. */
1196-
if (non_downgraded) {
1197-
sv_catpvn_nomg(sv, non_downgraded, non_downgraded_len);
1198-
}
11991164
}
12001165

12011166
SvTAINT(sv);

0 commit comments

Comments
 (0)