Skip to content

Commit 51fbc1c

Browse files
committed
utf8_to_uv_msgs: Convert switch case to use macro
By changing flags earlier in the function, we can convert this case in a switch to use the macro introduced in the previous commit
1 parent 2a00b11 commit 51fbc1c

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

utf8.c

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1832,7 +1832,17 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
18321832
if (UTF8_IS_SYNTACTIC_START_BYTE(s0)) {
18331833
overlong_detect_length = is_utf8_overlong(s0, s - s0);
18341834
if (UNLIKELY(overlong_detect_length > 0)) {
1835-
possible_problems |= UTF8_GOT_LONG;
1835+
1836+
/* Two flags control the same malformation. The more restrictive
1837+
* and less likely one causes the other one to be set as well, so
1838+
* as to simplify the code below. */
1839+
if (UNLIKELY(flags & UTF8_ALLOW_LONG_AND_ITS_VALUE)) {
1840+
possible_problems |= UTF8_GOT_LONG_WITH_VALUE;
1841+
flags |= UTF8_ALLOW_LONG;
1842+
}
1843+
else {
1844+
possible_problems |= UTF8_GOT_LONG;
1845+
}
18361846
}
18371847
}
18381848

@@ -2236,11 +2246,8 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22362246
}
22372247

22382248
case UTF8_GOT_LONG:
2239-
2240-
if (! (flags & ( UTF8_ALLOW_LONG
2241-
|UTF8_ALLOW_LONG_AND_ITS_VALUE)))
2242-
{
2243-
if (PACK_WARN(WARN_UTF8,,)) {
2249+
case UTF8_GOT_LONG_WITH_VALUE:
2250+
COMMON_DEFAULT_REJECTS(,);
22442251

22452252
/* These error types cause 'input_uv' to be something
22462253
* that isn't what was intended, so can't use it in the
@@ -2284,9 +2291,6 @@ Perl_utf8_to_uv_msgs_helper_(const U8 * const s0,
22842291
points */
22852292
UNI_TO_NATIVE(input_uv));
22862293
}
2287-
}
2288-
}
2289-
22902294
break;
22912295

22922296
case UTF8_GOT_SURROGATE:

0 commit comments

Comments
 (0)