Skip to content

Commit 678e40b

Browse files
committed
pp_pack: utf8_to_byte: Use 'uv' form, not 'uvchr'
This converts a call to utf8n_to_uvchr() to instead use utf8_to_uv_flags(). The previous code thought it was checking for failure and croaking when it occurred, but was checking the wrong way so that it never could fail. And now it does a proper check and can fail, which was the original intent.
1 parent 43b31fd commit 678e40b

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

pp_pack.c

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -253,12 +253,14 @@ utf8_to_byte(pTHX_ const char **s, const char *end, I32 datumtype)
253253
if (*s >= end) {
254254
goto croak;
255255
}
256-
val = utf8n_to_uvchr((U8 *) *s, end-*s, &retlen,
257-
ckWARN(WARN_UTF8) ? 0 : UTF8_ALLOW_ANY);
258-
if (retlen == (STRLEN) -1)
256+
if (! utf8_to_uv_flags((U8 *) *s, (U8 *) end, &val, &retlen,
257+
ckWARN(WARN_UTF8) ? 0 : UTF8_ALLOW_ANY))
258+
{
259259
croak:
260260
croak("Malformed UTF-8 string in '%c' format in unpack",
261261
(int) TYPE_NO_MODIFIERS(datumtype));
262+
}
263+
262264
if (val >= 0x100) {
263265
ck_warner(packWARN(WARN_UNPACK),
264266
"Character in '%c' format wrapped in unpack",

0 commit comments

Comments
 (0)