]> granicus.if.org Git - php/commitdiff
Fix cp950 pua check
authorNikita Popov <nikita.ppv@gmail.com>
Wed, 22 Nov 2017 22:47:18 +0000 (23:47 +0100)
committerNikita Popov <nikita.ppv@gmail.com>
Wed, 22 Nov 2017 22:47:18 +0000 (23:47 +0100)
One set of parenthesis was missing, causing a legitimate compiler
warnings. In the end it doesn't actually matter, because it just
ends up doing an unnecessary check in the w > 0 case.

This fixes the logic and moves it out into a separate functions,
to be a bit more readable.

ext/mbstring/libmbfl/filters/mbfilter_big5.c

index 21aac8ea7bc0b3ba08b001cb44656b288ffa213f..6b845f2bf9d29dc775a32c634646ddb753186c2d 100644 (file)
@@ -142,6 +142,17 @@ static unsigned short cp950_pua_tbl[][4] = {
        {0xf70f,0xf848,0xc740,0xc8fe},
 };
 
+static inline int is_in_cp950_pua(int c1, int c) {
+       if ((c1 >= 0xfa && c1 <= 0xfe) || (c1 >= 0x8e && c1 <= 0xa0) ||
+                       (c1 >= 0x81 && c1 <= 0x8d) || (c1 >= 0xc7 && c1 <= 0xc8)) {
+               return (c > 0x39 && c < 0x7f) || (c > 0xa0 && c < 0xff);
+       }
+       if (c1 == 0xc6) {
+               return c > 0xa0 && c < 0xff;
+       }
+       return 0;
+}
+
 /*
  * Big5 => wchar
  */
@@ -190,11 +201,7 @@ mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter)
 
                        if (filter->from->no_encoding == mbfl_no_encoding_cp950) {
                                /* PUA for CP950 */
-                               if (w <= 0 &&
-                                       (((c1 >= 0xfa && c1 <= 0xfe) || (c1 >= 0x8e && c1 <= 0xa0) ||
-                                         (c1 >= 0x81 && c1 <= 0x8d) ||(c1 >= 0xc7 && c1 <= 0xc8))
-                                        && ((c > 0x39 && c < 0x7f) || (c > 0xa0 && c < 0xff))) ||
-                                       ((c1 == 0xc6) && (c > 0xa0 && c < 0xff))) {
+                               if (w <= 0 && is_in_cp950_pua(c1, c)) {
                                        c2 = c1 << 8 | c;
                                        for (k = 0; k < sizeof(cp950_pua_tbl)/(sizeof(unsigned short)*4); k++) {
                                                if (c2 >= cp950_pua_tbl[k][2] && c2 <= cp950_pua_tbl[k][3]) {