Skip to content

Commit

Permalink
Fix EBCIDIC deficiency in uvoffuni_to_utf8_flags_msgs
Browse files Browse the repository at this point in the history
By adjusting the case labels, and inserting an extra EBCDIC-only case,
the code can be made to not, e.g. test for surrogates on UTF-EBCDIC
strings that are too short for those.

This is a minor issue, but this is a minor fix.
  • Loading branch information
khwilliamson committed Jun 14, 2021
1 parent b9394a0 commit e8ac68e
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions utf8.c
Expand Up @@ -274,14 +274,14 @@ Perl_uvoffuni_to_utf8_flags_msgs(pTHX_ U8 *d, UV input_uv, const UV flags, HV**

default:
p = d + utf8_skip - 1;
while (p >= d + 4) {
while (p >= d + 4 + ONE_IF_EBCDIC_ZERO_IF_NOT) {
*p-- = I8_TO_NATIVE_UTF8((shifted_uv & MASK) | MARK);
shifted_uv >>= SHIFT;
}

/* FALLTHROUGH */

case 4:
case 4 + ONE_IF_EBCDIC_ZERO_IF_NOT:
if (UNLIKELY(UNICODE_IS_SUPER(input_uv))) {
if (UNLIKELY( input_uv > MAX_LEGAL_CP
&& ! (flags & UNICODE_ALLOW_ABOVE_IV_MAX)))
Expand Down Expand Up @@ -326,11 +326,12 @@ Perl_uvoffuni_to_utf8_flags_msgs(pTHX_ U8 *d, UV input_uv, const UV flags, HV**
}
}

d[3] = I8_TO_NATIVE_UTF8((shifted_uv & MASK) | MARK);
d[3 + ONE_IF_EBCDIC_ZERO_IF_NOT]
= I8_TO_NATIVE_UTF8((shifted_uv & MASK) | MARK);
shifted_uv >>= SHIFT;
/* FALLTHROUGH */

case 3:
case 3 + ONE_IF_EBCDIC_ZERO_IF_NOT:
if (input_uv >= UNICODE_SURROGATE_FIRST) {
if (UNLIKELY(UNICODE_IS_NONCHAR(input_uv))) {
HANDLE_UNICODE_NONCHAR(input_uv, flags, msgs);
Expand All @@ -340,10 +341,20 @@ Perl_uvoffuni_to_utf8_flags_msgs(pTHX_ U8 *d, UV input_uv, const UV flags, HV**
}
}

d[2 + ONE_IF_EBCDIC_ZERO_IF_NOT]
= I8_TO_NATIVE_UTF8((shifted_uv & MASK) | MARK);
shifted_uv >>= SHIFT;
/* FALLTHROUGH */

#ifdef EBCDIC

case 3:
d[2] = I8_TO_NATIVE_UTF8((shifted_uv & MASK) | MARK);
shifted_uv >>= SHIFT;
/* FALLTHROUGH */

#endif

case 2:
d[1] = I8_TO_NATIVE_UTF8((shifted_uv & MASK) | MARK);
shifted_uv >>= SHIFT;
Expand Down

0 comments on commit e8ac68e

Please sign in to comment.