Skip to content

Commit dc1ba61

Browse files
committed
Simplify code for converting UTF-8
An overly complex boolean test was used to check if a 3-byte code unit was valid. Convert it to an equivalent test with fewer terms.
1 parent 85690ae commit dc1ba61

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

ext/mbstring/libmbfl/filters/mbfilter_utf8.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,7 @@ static size_t mb_utf8_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf
240240
if ((e - p) >= 2) {
241241
unsigned char c2 = *p++;
242242
unsigned char c3 = *p++;
243-
if ((c2 & 0xC0) != 0x80 || !((c2 >= 0x80 && c2 <= 0xBF) && ((c == 0xE0 && c2 >= 0xA0) || (c == 0xED && c2 < 0xA0) || (c > 0xE0 && c != 0xED)))) {
243+
if ((c2 & 0xC0) != 0x80 || (c == 0xE0 && c2 < 0xA0) || (c == 0xED && c2 >= 0xA0)) {
244244
*out++ = MBFL_BAD_INPUT;
245245
p -= 2;
246246
} else if ((c3 & 0xC0) != 0x80) {
@@ -285,7 +285,7 @@ static size_t mb_utf8_to_wchar(unsigned char **in, size_t *in_len, uint32_t *buf
285285
*out++ = MBFL_BAD_INPUT;
286286
if (p < e) {
287287
unsigned char c2 = *p;
288-
if ((c == 0xF0 && c2 >= 0x90) || (c == 0xF4 && c2 < 0x90) || c == 0xF2 || c == 0xF3) {
288+
if ((c == 0xF0 && c2 >= 0x90) || (c == 0xF4 && c2 < 0x90)) {
289289
while (p < e && (*p & 0xC0) == 0x80) {
290290
p++;
291291
}

0 commit comments

Comments
 (0)