]> granicus.if.org Git - php/commitdiff
Remove useless validity check when converting UTF-16LE -> wchar
authorAlex Dowad <alexinbeijing@gmail.com>
Sun, 6 Sep 2020 10:09:02 +0000 (12:09 +0200)
committerAlex Dowad <alexinbeijing@gmail.com>
Tue, 13 Oct 2020 04:12:37 +0000 (06:12 +0200)
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

index e4c9be9cbd7f782e53ec1539e315a36dccc2edc4..7a9c70377e3ac067d97664eb90684330c4ff0b5d 100644 (file)
@@ -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;
        }