Skip to content

Commit 48972dd

Browse files
committedJan 23, 2025
doop.c Use new utf8_to_uv_or_die()
This replaces the older forms. For two of the instances, this gives equivalent functionality, where they croaked if an operand to tr/// was malformed. For the other instances, it didn't croak, but now does. This makes the behavior consistent for tr///, as all the affected instances are supposed to be equivalent. For performance reasons, one or another of the functions would be called, and depending on which one the same input would croak or not.
1 parent 2b29c5b commit 48972dd

File tree

1 file changed

+5
-12
lines changed

1 file changed

+5
-12
lines changed
 

‎doop.c

+5-12
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ S_do_trans_simple(pTHX_ SV * const sv, const OPtrans_map * const tbl)
8282
short ch;
8383

8484
/* Need to check this, otherwise 128..255 won't match */
85-
const UV c = utf8n_to_uvchr(s, send - s, &ulen, UTF8_ALLOW_DEFAULT);
85+
const UV c = utf8_to_uv_or_die(s, send, &ulen);
8686
if (c < 0x100 && (ch = tbl->map[c]) >= 0) {
8787
matches++;
8888
d = uv_to_utf8(d, (UV)ch);
@@ -149,7 +149,7 @@ S_do_trans_count(pTHX_ SV * const sv, const OPtrans_map * const tbl)
149149
const bool complement = cBOOL(PL_op->op_private & OPpTRANS_COMPLEMENT);
150150
while (s < send) {
151151
STRLEN ulen;
152-
const UV c = utf8n_to_uvchr(s, send - s, &ulen, UTF8_ALLOW_DEFAULT);
152+
const UV c = utf8_to_uv_or_die(s, send, &ulen);
153153
if (c < 0x100) {
154154
if (tbl->map[c] >= 0)
155155
matches++;
@@ -266,8 +266,7 @@ S_do_trans_complex(pTHX_ SV * const sv, const OPtrans_map * const tbl)
266266

267267
while (s < send) {
268268
STRLEN len;
269-
const UV comp = utf8n_to_uvchr(s, send - s, &len,
270-
UTF8_ALLOW_DEFAULT);
269+
const UV comp = utf8_to_uv_or_die(s, send, &len);
271270
UV ch;
272271
short sch;
273272

@@ -371,10 +370,7 @@ S_do_trans_count_invmap(pTHX_ SV * const sv, AV * const invmap)
371370
s_len = 1;
372371
}
373372
else {
374-
from = utf8_to_uvchr_buf(s, send, &s_len);
375-
if (from == 0 && *s != '\0') {
376-
force_out_malformed_utf8_message_(s, send, 0, MALFORMED_UTF8_DIE);
377-
}
373+
from = utf8_to_uv_or_die(s, send, &s_len);
378374
}
379375

380376
/* Look the code point up in the data structure for this tr/// to get
@@ -490,10 +486,7 @@ S_do_trans_invmap(pTHX_ SV * const sv, AV * const invmap)
490486
s_len = 1;
491487
}
492488
else {
493-
from = utf8_to_uvchr_buf(s, send, &s_len);
494-
if (from == 0 && *s != '\0') {
495-
force_out_malformed_utf8_message_(s, send, 0, MALFORMED_UTF8_DIE);
496-
}
489+
from = utf8_to_uv_or_die(s, send, &s_len);
497490
}
498491

499492
/* Look the code point up in the data structure for this tr/// to get

0 commit comments

Comments
 (0)
Please sign in to comment.