Skip to content

Commit f087bac

Browse files
committed
pp_pack: utf8_to_bytes: Use 'uv' form, not 'uvchr'
Like previous commits, this converts a call to utf8n_to_uvchr() to instead use utf8_to_uv_flags(). Unlike those commits, the previous code did in fact properly check for failure. But upon failure, it semi-unsafely assumed the start byte was accurate as to the intended byte length of the input character. (It did check that the returned value did not go past the end of the buffer, by using UTF8_SAFE_SKIP() ). The new function call always returns the correct number of bytes, so just use that instead of trying to recompute it. The mechanism for deteriming failure no longer depends on the CHECK_ONLY flag, so that is removed.
1 parent 78defb0 commit f087bac

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

pp_pack.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -282,26 +282,26 @@ S_utf8_to_bytes(pTHX_ const char **s, const char *end, const char *buf, SSize_t
282282
STRLEN retlen;
283283
const char *from = *s;
284284
int bad = 0;
285-
const U32 flags = ckWARN(WARN_UTF8) ?
286-
UTF8_CHECK_ONLY : (UTF8_CHECK_ONLY | UTF8_ALLOW_ANY);
285+
const U32 flags = ckWARN(WARN_UTF8) ? 0 : UTF8_ALLOW_ANY;
287286
const bool needs_swap = NEEDS_SWAP(datumtype);
288287

289288
if (UNLIKELY(needs_swap))
290289
buf += buf_len;
291290

292291
for (; buf_len > 0; buf_len--) {
293292
if (from >= end) return FALSE;
294-
val = utf8n_to_uvchr((U8 *) from, end-from, &retlen, flags);
295-
if (retlen == (STRLEN) -1) {
296-
from += UTF8_SAFE_SKIP(from, end);
293+
if (! utf8_to_uv_flags((U8 *) from, (U8 *) end, &val, &retlen, flags))
294+
{
297295
bad |= 1;
298-
} else from += retlen;
296+
}
299297

300298
if (val >= 0x100) {
301299
bad |= 2;
302300
val = (U8) val;
303301
}
304302

303+
from += retlen;
304+
305305
if (UNLIKELY(needs_swap))
306306
*(U8 *)--buf = (U8)val;
307307
else

0 commit comments

Comments
 (0)