From aabbee23187af5590424b2e291fb26d62ef8ddf0 Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Sun, 6 Sep 2020 12:09:02 +0200 Subject: [PATCH] Remove useless validity check when converting UTF-16LE -> wchar The check ensures that the decoded codepoint is between 0x10000-0x10FFFF, which is the valid range which can be encoded in a UTF-16 surrogate pair. However, just looking at the code, it's obvious that this will be true. First of all, 0x10000 is added to the decoded codepoint on the previous line, so how could it be less than 0x10000? Further, even if the 20 data bits already decoded were 0xFFFFF (all ones), when you add 0x10000, it comes to 0x10FFFF, which is the very top of the valid range. So how could the decoded codepoint be more than 0x10FFFF? It can't. --- ext/mbstring/libmbfl/filters/mbfilter_utf16.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf16.c b/ext/mbstring/libmbfl/filters/mbfilter_utf16.c index e4c9be9cbd..7a9c70377e 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf16.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf16.c @@ -290,11 +290,7 @@ int mbfl_filt_conv_utf16le_wchar(int c, mbfl_convert_filter *filter) case 3: filter->status = 0; int n = filter->cache + ((c & 0x3) << 8) + 0x10000; - if (n >= MBFL_WCSPLANE_SUPMIN && n < MBFL_WCSPLANE_SUPMAX) { - CK((*filter->output_function)(n, filter->data)); - } else { /* illegal character */ - CK((*filter->output_function)((n & MBFL_WCSGROUP_MASK) | MBFL_WCSGROUP_THROUGH, filter->data)); - } + CK((*filter->output_function)(n, filter->data)); break; } -- 2.40.0