From 626f0fec5498ccb2e20dc7cf2942e85b9523ba2a Mon Sep 17 00:00:00 2001 From: Alex Dowad Date: Fri, 30 Jul 2021 11:44:18 +0200 Subject: [PATCH] Remove some dead code from mbstring mbstring has a great deal of dead code. Some common types are: - Default switch clauses which will never be taken - If clauses intended to convert codepoints which were not present in a conversion table... but the codepoint in question *is* in the table, so the if clause is not needed. - Bounds checks in places where it is not possible for a value to ever be out of bounds. - Checks to see if an unmatched Unicode codepoint is in CP932 extension range 3... but every codepoint in range 3 is also in range 2, so no codepoint will ever be matched and converted by that code. --- ext/mbstring/libmbfl/filters/mbfilter_big5.c | 4 +- .../libmbfl/filters/mbfilter_cp5022x.c | 48 ++--------- .../libmbfl/filters/mbfilter_cp51932.c | 4 +- ext/mbstring/libmbfl/filters/mbfilter_cp932.c | 4 +- ext/mbstring/libmbfl/filters/mbfilter_cp936.c | 16 +--- .../libmbfl/filters/mbfilter_euc_cn.c | 25 +++--- .../libmbfl/filters/mbfilter_euc_jp.c | 6 +- .../libmbfl/filters/mbfilter_euc_jp_win.c | 7 +- .../libmbfl/filters/mbfilter_euc_kr.c | 22 ++---- .../libmbfl/filters/mbfilter_euc_tw.c | 4 +- .../libmbfl/filters/mbfilter_gb18030.c | 28 ++----- ext/mbstring/libmbfl/filters/mbfilter_hz.c | 27 +++---- .../libmbfl/filters/mbfilter_iso2022_jp_ms.c | 4 - .../libmbfl/filters/mbfilter_iso2022_kr.c | 20 ++--- .../filters/mbfilter_iso2022jp_mobile.c | 4 - ext/mbstring/libmbfl/filters/mbfilter_jis.c | 15 +--- ext/mbstring/libmbfl/filters/mbfilter_sjis.c | 2 - .../libmbfl/filters/mbfilter_sjis_2004.c | 79 ++++++++----------- .../libmbfl/filters/mbfilter_sjis_mac.c | 13 +-- .../libmbfl/filters/mbfilter_sjis_mobile.c | 10 --- ext/mbstring/libmbfl/filters/mbfilter_uhc.c | 4 +- ext/mbstring/libmbfl/filters/mbfilter_utf7.c | 26 ++---- .../libmbfl/filters/mbfilter_utf7imap.c | 9 +-- ext/mbstring/libmbfl/filters/mbfilter_utf8.c | 5 +- .../libmbfl/filters/mbfilter_utf8_mobile.c | 5 +- ext/mbstring/libmbfl/mbfl/mbfilter.c | 2 - 26 files changed, 108 insertions(+), 285 deletions(-) diff --git a/ext/mbstring/libmbfl/filters/mbfilter_big5.c b/ext/mbstring/libmbfl/filters/mbfilter_big5.c index c4f77a26fc4..561ab8c225a 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_big5.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_big5.c @@ -239,9 +239,7 @@ int mbfl_filt_conv_big5_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c b/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c index 7f1994077ab..a69c4c5426a 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp5022x.c @@ -298,9 +298,7 @@ retry: } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -322,16 +320,13 @@ static int mbfl_filt_conv_cp5022x_wchar_flush(mbfl_convert_filter *filter) static int mbfl_filt_conv_wchar_cp50220(int c, mbfl_convert_filter *filter) { - int mode = MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE, second = 0; + int mode = MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE; bool consumed = false; if (filter->cache) { - int s = mbfl_convert_kana(filter->cache, c, &consumed, &second, mode); + int s = mbfl_convert_kana(filter->cache, c, &consumed, NULL, mode); filter->cache = consumed ? 0 : c; mbfl_filt_conv_wchar_cp50221(s, filter); - if (second) { - mbfl_filt_conv_wchar_cp50221(second, filter); - } } else if (c == 0) { /* This case has to be handled separately, since `filter->cache == 0` means * no codepoint is cached */ @@ -345,14 +340,11 @@ static int mbfl_filt_conv_wchar_cp50220(int c, mbfl_convert_filter *filter) static int mbfl_filt_conv_wchar_cp50220_flush(mbfl_convert_filter *filter) { - int mode = MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE, second = 0; + int mode = MBFL_FILT_TL_HAN2ZEN_KATAKANA | MBFL_FILT_TL_HAN2ZEN_GLUE; if (filter->cache) { - int s = mbfl_convert_kana(filter->cache, 0, NULL, &second, mode); + int s = mbfl_convert_kana(filter->cache, 0, NULL, NULL, mode); mbfl_filt_conv_wchar_cp50221(s, filter); - if (second) { - mbfl_filt_conv_wchar_cp50221(s, filter); - } filter->cache = 0; } @@ -432,21 +424,6 @@ int mbfl_filt_conv_wchar_cp50221(int c, mbfl_convert_filter *filter) } } - if (s < 0) { - const int cp932ext3_ucs_table_size = - cp932ext3_ucs_table_max - cp932ext3_ucs_table_min; - const int limit = cp932ext3_ucs_table_size > - cp932ext3_eucjp_table_size ? - cp932ext3_eucjp_table_size: - cp932ext3_ucs_table_size; - for (i = 0; i < limit; i++) { - if (c == cp932ext3_ucs_table[i]) { - s = cp932ext3_eucjp_table[i]; - break; - } - } - } - if (c == 0) { s = 0; } else if (s <= 0) { @@ -564,21 +541,6 @@ int mbfl_filt_conv_wchar_cp50222(int c, mbfl_convert_filter *filter) } } - if (s <= 0) { - const int cp932ext3_ucs_table_size = - cp932ext3_ucs_table_max - cp932ext3_ucs_table_min; - const int limit = cp932ext3_ucs_table_size > - cp932ext3_eucjp_table_size ? - cp932ext3_eucjp_table_size: - cp932ext3_ucs_table_size; - for (i = 0; i < limit; i++) { - if (c == cp932ext3_ucs_table[i]) { - s = cp932ext3_eucjp_table[i]; - break; - } - } - } - if (c == 0) { s = 0; } else if (s <= 0) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c b/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c index 9bfb75fee8c..c0069a93fb9 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp51932.c @@ -163,9 +163,7 @@ mbfl_filt_conv_cp51932_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp932.c b/ext/mbstring/libmbfl/filters/mbfilter_cp932.c index 10559b593be..9c24fa64494 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp932.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp932.c @@ -203,9 +203,7 @@ mbfl_filt_conv_cp932_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_cp936.c b/ext/mbstring/libmbfl/filters/mbfilter_cp936.c index c53bfe42a7b..22a759ee79f 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_cp936.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_cp936.c @@ -142,24 +142,16 @@ int mbfl_filt_conv_cp936_wchar(int c, mbfl_convert_filter *filter) if (w <= 0) { if (c1 < 0xff && c1 > 0x80 && c >= 0x40 && c < 0xff && c != 0x7f) { - w = (c1 - 0x81)*192 + (c - 0x40); - if (w >= 0 && w < cp936_ucs_table_size) { - w = cp936_ucs_table[w]; - if (!w) - w = MBFL_BAD_INPUT; - } else { - w = MBFL_BAD_INPUT; - } - CK((*filter->output_function)(w, filter->data)); + w = (c1 - 0x81)*192 + c - 0x40; + ZEND_ASSERT(w < cp936_ucs_table_size); + CK((*filter->output_function)(cp936_ucs_table[w], filter->data)); } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c index ecde251b119..01c48e433ee 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_cn.c @@ -108,19 +108,16 @@ int mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter) filter->status = 0; c1 = filter->cache; if (c > 0xA0 && c < 0xFF) { - w = (c1 - 0x81)*192 + (c - 0x40); - if (w >= 0 && w < cp936_ucs_table_size) { - if (w == 0x1864) { - w = 0x30FB; - } else if (w == 0x186A) { - w = 0x2015; - } else if ((w >= 0x1921 && w <= 0x192A) || w == 0x1963 || (w >= 0x1C59 && w <= 0x1C7E) || (w >= 0x1DBB && w <= 0x1DC4)) { - w = 0; - } else { - w = cp936_ucs_table[w]; - } - } else { + w = (c1 - 0x81)*192 + c - 0x40; + ZEND_ASSERT(w < cp936_ucs_table_size); + if (w == 0x1864) { + w = 0x30FB; + } else if (w == 0x186A) { + w = 0x2015; + } else if ((w >= 0x1921 && w <= 0x192A) || w == 0x1963 || (w >= 0x1C59 && w <= 0x1C7E) || (w >= 0x1DBB && w <= 0x1DC4)) { w = 0; + } else { + w = cp936_ucs_table[w]; } if (w <= 0) { @@ -133,9 +130,7 @@ int mbfl_filt_conv_euccn_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c index c963716d432..7dd095862ec 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp.c @@ -166,9 +166,7 @@ mbfl_filt_conv_eucjp_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -209,8 +207,6 @@ mbfl_filt_conv_wchar_eucjp(int c, mbfl_convert_filter *filter) if (s <= 0) { if (c == 0xff3c) { /* FULLWIDTH REVERSE SOLIDUS */ s = 0x2140; - } else if (c == 0xff5e) { /* FULLWIDTH TILDE */ - s = 0x2141; } else if (c == 0x2225) { /* PARALLEL TO */ s = 0x2142; } else if (c == 0xff0d) { /* FULLWIDTH HYPHEN-MINUS */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c index 02ee1b1c59a..1209e63148f 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_jp_win.c @@ -167,6 +167,7 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) filter->status++; filter->cache = c; break; + case 4: /* got 0x8f, X 0212 second char */ filter->status = 0; c1 = filter->cache; @@ -211,9 +212,7 @@ int mbfl_filt_conv_eucjpwin_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -271,8 +270,6 @@ int mbfl_filt_conv_wchar_eucjpwin(int c, mbfl_convert_filter *filter) s1 = 0x213D; } else if (c == 0xff3c) { /* FULLWIDTH REVERSE SOLIDUS */ s1 = 0x2140; - } else if (c == 0xff5e) { /* FULLWIDTH TILDE */ - s1 = 0x2141; } else if (c == 0x2225) { /* PARALLEL TO */ s1 = 0x2142; } else if (c == 0xff0d) { /* FULLWIDTH HYPHEN-MINUS */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c index a824909f05c..8362138d15a 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_kr.c @@ -114,19 +114,13 @@ int mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter) } if (flag > 0 && c >= 0xa1 && c <= 0xfe) { if (flag == 1) { /* 1st: 0xa1..0xc6, 2nd: 0x41..0x7a, 0x81..0xfe */ - w = (c1 - 0xa1)*190 + (c - 0x41); - if (w >= 0 && w < uhc2_ucs_table_size) { - w = uhc2_ucs_table[w]; - } else { - w = 0; - } + w = (c1 - 0xa1)*190 + c - 0x41; + ZEND_ASSERT(w < uhc2_ucs_table_size); + w = uhc2_ucs_table[w]; } else { /* 1st: 0xc7..0xc8,0xca..0xfe, 2nd: 0xa1..0xfe */ - w = (c1 - 0xc7)*94 + (c - 0xa1); - if (w >= 0 && w < uhc3_ucs_table_size) { - w = uhc3_ucs_table[w]; - } else { - w = 0; - } + w = (c1 - 0xc7)*94 + c - 0xa1; + ZEND_ASSERT(w < uhc3_ucs_table_size); + w = uhc3_ucs_table[w]; } if (w <= 0) { @@ -138,9 +132,7 @@ int mbfl_filt_conv_euckr_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c b/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c index 187ac8ad9d5..e2c3bceaa50 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_euc_tw.c @@ -184,9 +184,7 @@ int mbfl_filt_conv_euctw_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c b/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c index 5ab2bc15af6..4a8939523a5 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_gb18030.c @@ -168,15 +168,9 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) (c1 >= 0x81 && c1 <= 0xa0 && c >= 0x40 && c <= 0xfe && c != 0x7f) || (c1 >= 0xaa && c1 <= 0xfe && c >= 0x40 && c <= 0xa0 && c != 0x7f) || (c1 >= 0xa8 && c1 <= 0xa9 && c >= 0x40 && c <= 0xa0 && c != 0x7f)) { - w = (c1 - 0x81)*192 + (c - 0x40); - if (w >= 0 && w < cp936_ucs_table_size) { - w = cp936_ucs_table[w]; - if (!w) - w = MBFL_BAD_INPUT; - } else { - w = MBFL_BAD_INPUT; - } - CK((*filter->output_function)(w, filter->data)); + w = (c1 - 0x81)*192 + c - 0x40; + ZEND_ASSERT(w < cp936_ucs_table_size); + CK((*filter->output_function)(cp936_ucs_table[w], filter->data)); } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } @@ -211,10 +205,6 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) w = (((c1 - 0x81)*10 + (c2 - 0x30))*126 + (c3 - 0x81))*10 + (c - 0x30); if (w >= 0 && w <= 39419) { k = mbfl_bisec_srch(w, mbfl_gb2uni_tbl, mbfl_gb_uni_max); - if (k < 0) { - CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); - return 0; - } w += mbfl_gb_uni_ofst[k]; } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); @@ -227,9 +217,7 @@ int mbfl_filt_conv_gb18030_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -370,12 +358,8 @@ int mbfl_filt_conv_wchar_gb18030(int c, mbfl_convert_filter *filter) s1 = c1 + 0x90; } - if (s <= 0) { - if (c == 0) { - s = 0; - } else { - s = -1; - } + if (c == 0) { + s = 0; } if (s >= 0) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_hz.c b/ext/mbstring/libmbfl/filters/mbfilter_hz.c index 14edf64a7bb..722d73dd40c 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_hz.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_hz.c @@ -95,20 +95,17 @@ int mbfl_filt_conv_hz_wchar(int c, mbfl_convert_filter *filter) c1 = filter->cache; if (c1 > 0x20 && c1 < 0x7F && c > 0x20 && c < 0x7F) { s = (c1 - 1)*192 + c + 0x40; /* GB2312 */ - if (s >= 0 && s < cp936_ucs_table_size) { - if (s == 0x1864) { - w = 0x30FB; - } else if (s == 0x186A) { - w = 0x2015; - } else if (s == 0x186C) { - w = 0x2225; - } else if ((s >= 0x1920 && s <= 0x192A) || s == 0x1963 || (s >= 0x1C60 && s <= 0x1C7F) || (s >= 0x1DBB && s <= 0x1DC4)) { - w = 0; - } else { - w = cp936_ucs_table[s]; - } - } else { + ZEND_ASSERT(s < cp936_ucs_table_size); + if (s == 0x1864) { + w = 0x30FB; + } else if (s == 0x186A) { + w = 0x2015; + } else if (s == 0x186C) { + w = 0x2225; + } else if ((s >= 0x1920 && s <= 0x192A) || s == 0x1963 || (s >= 0x1C60 && s <= 0x1C7F) || (s >= 0x1DBB && s <= 0x1DC4)) { w = 0; + } else { + w = cp936_ucs_table[s]; } if (w <= 0) { @@ -139,9 +136,7 @@ int mbfl_filt_conv_hz_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c index cc7cd90a1d5..41d4088c475 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_jp_ms.c @@ -258,12 +258,8 @@ int mbfl_filt_conv_wchar_2022jpms(int c, mbfl_convert_filter *filter) if (s1 <= 0) { if (c == 0xA5) { /* YEN SIGN */ s1 = 0x216F; /* FULLWIDTH YEN SIGN */ - } else if (c == 0x203E) { /* OVER LINE */ - s1 = 0x2131; /* FULLWIDTH MACRON */ } else if (c == 0xFF3C) { /* FULLWIDTH REVERSE SOLIDUS */ s1 = 0x2140; - } else if (c == 0xFF5E) { /* FULLWIDTH TILDE */ - s1 = 0x2141; } else if (c == 0x2225) { /* PARALLEL TO */ s1 = 0x2142; } else if (c == 0xFF0D) { /* FULLWIDTH HYPHEN-MINUS */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c index ba1177a2ea9..f012656b197 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_iso2022_kr.c @@ -113,19 +113,13 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) if (flag == 1) { if (c1 != 0x22 || c <= 0x65) { w = (c1 - 0x21)*190 + (c - 0x41) + 0x80; - if (w >= 0 && w < uhc2_ucs_table_size) { - w = uhc2_ucs_table[w]; - } else { - w = 0; - } + ZEND_ASSERT(w < uhc2_ucs_table_size); + w = uhc2_ucs_table[w]; } } else { - w = (c1 - 0x47)*94 + (c - 0x21); - if (w >= 0 && w < uhc3_ucs_table_size) { - w = uhc3_ucs_table[w]; - } else { - w = 0; - } + w = (c1 - 0x47)*94 + c - 0x21; + ZEND_ASSERT(w < uhc3_ucs_table_size); + w = uhc3_ucs_table[w]; } if (w <= 0) { @@ -162,9 +156,7 @@ int mbfl_filt_conv_2022kr_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c index febfd84ddc5..3d289f11915 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_iso2022jp_mobile.c @@ -268,12 +268,8 @@ int mbfl_filt_conv_wchar_2022jp_mobile(int c, mbfl_convert_filter *filter) if (s1 <= 0) { if (c == 0xA5) { /* YEN SIGN */ s1 = 0x216F; /* FULLWIDTH YEN SIGN */ - } else if (c == 0x203E) { /* OVER LINE */ - s1 = 0x2131; /* FULLWIDTH MACRON */ } else if (c == 0xFF3C) { /* FULLWIDTH REVERSE SOLIDUS */ s1 = 0x2140; - } else if (c == 0xFF5E) { /* FULLWIDTH TILDE */ - s1 = 0x2141; } else if (c == 0x2225) { /* PARALLEL TO */ s1 = 0x2142; } else if (c == 0xFF0D) { /* FULLWIDTH HYPHEN-MINUS */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_jis.c b/ext/mbstring/libmbfl/filters/mbfilter_jis.c index 6d876bbdfad..9de18964cce 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_jis.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_jis.c @@ -251,9 +251,7 @@ retry: } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -318,14 +316,6 @@ mbfl_filt_conv_wchar_jis(int c, mbfl_convert_filter *filter) } filter->status = 0; CK((*filter->output_function)(s, filter->data)); - } else if (s < 0x100) { /* kana */ - if ((filter->status & 0xff00) != 0x100) { - CK((*filter->output_function)(0x1b, filter->data)); /* ESC */ - CK((*filter->output_function)(0x28, filter->data)); /* '(' */ - CK((*filter->output_function)(0x49, filter->data)); /* 'I' */ - } - filter->status = 0x100; - CK((*filter->output_function)(s & 0x7f, filter->data)); } else if (s < 0x8080) { /* X 0208 */ if ((filter->status & 0xff00) != 0x200) { CK((*filter->output_function)(0x1b, filter->data)); /* ESC */ @@ -380,11 +370,10 @@ mbfl_filt_conv_wchar_2022jp(int c, mbfl_convert_filter *filter) } else if (c >= ucs_r_jis_table_min && c < ucs_r_jis_table_max) { s = ucs_r_jis_table[c - ucs_r_jis_table_min]; } + if (s <= 0) { if (c == 0xa5) { /* YEN SIGN */ s = 0x1005c; - } else if (c == 0x203e) { /* OVER LINE */ - s = 0x1007e; } else if (c == 0xff3c) { /* FULLWIDTH REVERSE SOLIDUS */ s = 0x2140; } else if (c == 0x2225) { /* PARALLEL TO */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis.c index 188f162bf87..ef59026a9ee 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis.c @@ -221,8 +221,6 @@ int mbfl_filt_conv_wchar_sjis(int c, mbfl_convert_filter *filter) s1 = 0x5C; } else if (c == 0xFF3C) { /* FULLWIDTH REVERSE SOLIDUS */ s1 = 0x2140; - } else if (c == 0xFF5E) { /* FULLWIDTH TILDE */ - s1 = 0x2141; } else if (c == 0x2225) { /* PARALLEL TO */ s1 = 0x2142; } else if (c == 0xFF0D) { /* FULLWIDTH HYPHEN-MINUS */ diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c index a1d94693e8f..19602dd9da4 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis_2004.c @@ -209,43 +209,39 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) } w1 = (s1 << 8) | s2; - if (w1 >= 0x2121) { - /* conversion for combining characters */ - if ((w1 >= 0x2477 && w1 <= 0x2479) || (w1 >= 0x2479 && w1 <= 0x247B) || - (w1 >= 0x2577 && w1 <= 0x257E) || w1 == 0x2678 || w1 == 0x2B44 || - (w1 >= 0x2B48 && w1 <= 0x2B4F) || (w1 >= 0x2B65 && w1 <= 0x2B66)) { - k = mbfl_bisec_srch2(w1, jisx0213_u2_key, jisx0213_u2_tbl_len); - if (k >= 0) { - w = jisx0213_u2_tbl[2*k]; - CK((*filter->output_function)(w, filter->data)); - w = jisx0213_u2_tbl[2*k+1]; - } + /* conversion for combining characters */ + if ((w1 >= 0x2477 && w1 <= 0x2479) || (w1 >= 0x2479 && w1 <= 0x247B) || + (w1 >= 0x2577 && w1 <= 0x257E) || w1 == 0x2678 || w1 == 0x2B44 || + (w1 >= 0x2B48 && w1 <= 0x2B4F) || (w1 >= 0x2B65 && w1 <= 0x2B66)) { + k = mbfl_bisec_srch2(w1, jisx0213_u2_key, jisx0213_u2_tbl_len); + if (k >= 0) { + w = jisx0213_u2_tbl[2*k]; + CK((*filter->output_function)(w, filter->data)); + w = jisx0213_u2_tbl[2*k+1]; } - - /* conversion for BMP */ - if (w <= 0) { - w1 = (s1 - 0x21)*94 + s2 - 0x21; - if (w1 >= 0 && w1 < jisx0213_ucs_table_size) { - w = jisx0213_ucs_table[w1]; - } - } - - /* conversion for CJK Unified Ideographs ext.B (U+2XXXX) */ - if (w <= 0) { - w1 = (s1 << 8) | s2; - k = mbfl_bisec_srch2(w1, jisx0213_jis_u5_key, jisx0213_u5_tbl_len); - if (k >= 0) { - w = jisx0213_jis_u5_tbl[k] + 0x20000; - } - } - - if (w <= 0) { - w = MBFL_BAD_INPUT; - } - CK((*filter->output_function)(w, filter->data)); - } else { - CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); } + + /* conversion for BMP */ + if (w <= 0) { + w1 = (s1 - 0x21)*94 + s2 - 0x21; + if (w1 >= 0 && w1 < jisx0213_ucs_table_size) { + w = jisx0213_ucs_table[w1]; + } + } + + /* conversion for CJK Unified Ideographs ext.B (U+2XXXX) */ + if (w <= 0) { + w1 = (s1 << 8) | s2; + k = mbfl_bisec_srch2(w1, jisx0213_jis_u5_key, jisx0213_u5_tbl_len); + if (k >= 0) { + w = jisx0213_jis_u5_tbl[k] + 0x20000; + } + } + + if (w <= 0) { + w = MBFL_BAD_INPUT; + } + CK((*filter->output_function)(w, filter->data)); break; case 2: /* got 0x8e: EUC-JP-2004 kana */ @@ -297,11 +293,8 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) /* check for japanese chars in BMP */ s = (s1 + 94 + k)*94 + s2; - if (s >= 0 && s < jisx0213_ucs_table_size) { - w = jisx0213_ucs_table[s]; - } else { - w = 0; - } + ZEND_ASSERT(s < jisx0213_ucs_table_size); + w = jisx0213_ucs_table[s]; /* check for japanese chars in CJK Unified Ideographs ext.B (U+2XXXX) */ if (w <= 0) { @@ -408,9 +401,7 @@ int mbfl_filt_conv_jis2004_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -543,8 +534,6 @@ retry: } else { s1 = -1; } - } else if (s1 >= 0x9980) { - s1 = -1; } if (s1 >= 0) { diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c index 35d5bee59a8..e8116b6b8bd 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mac.c @@ -253,9 +253,7 @@ mbfl_filt_conv_sjis_mac_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -287,7 +285,6 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) // r: U+FF00 -> U+FFFF switch (filter->status) { - case 1: c1 = filter->cache; filter->cache = 0; @@ -368,7 +365,6 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) ZEND_FALLTHROUGH; case 0: - if (c >= ucs_a1_jis_table_min && c < ucs_a1_jis_table_max) { s1 = ucs_a1_jis_table[c - ucs_a1_jis_table_min]; if (c == 0x5c) { @@ -480,7 +476,6 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) } break; - case 2: c1 = filter->cache; filter->cache = 0; @@ -516,7 +511,6 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) CK(mbfl_filt_conv_illegal_output(c1, filter)); return mbfl_filt_conv_wchar_sjis_mac(c, filter); } - break; case 3: @@ -653,10 +647,9 @@ mbfl_filt_conv_wchar_sjis_mac(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c index 41097df304a..4eaa1c25575 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_sjis_mobile.c @@ -785,16 +785,6 @@ int mbfl_filt_conv_wchar_sjis_mobile(int c, mbfl_convert_filter *filter) } } - if (s1 <= 0) { - /* CP932 vendor ext3 (115ku - 119ku) */ - for (c1 = 0; c1 < cp932ext3_ucs_table_max - cp932ext3_ucs_table_min; c1++) { - if (c == cp932ext3_ucs_table[c1]) { - s1 = (((c1 / 94) + 0x93) << 8) + (c1 % 94) + 0x21; - break; - } - } - } - if (c == 0) { s1 = 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_uhc.c b/ext/mbstring/libmbfl/filters/mbfilter_uhc.c index 96be552729b..06300404b6e 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_uhc.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_uhc.c @@ -133,9 +133,7 @@ int mbfl_filt_conv_uhc_wchar(int c, mbfl_convert_filter *filter) CK((*filter->output_function)(w, filter->data)); break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf7.c b/ext/mbstring/libmbfl/filters/mbfilter_utf7.c index a5446afd8ae..c3144b47795 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf7.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf7.c @@ -163,11 +163,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) s &= 0x3ff; s |= (filter->cache & 0xfff0000) >> 6; filter->cache = n; - if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { - CK((*filter->output_function)(s, filter->data)); - } else { /* illegal character */ - CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); - } + CK((*filter->output_function)(s, filter->data)); } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = n; @@ -207,11 +203,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) s &= 0x3ff; s |= (filter->cache & 0xfff0000) >> 6; filter->cache = n; - if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { - CK((*filter->output_function)(s, filter->data)); - } else { /* illegal character */ - CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); - } + CK((*filter->output_function)(s, filter->data)); } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = n; @@ -245,11 +237,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) s &= 0x3ff; s |= (filter->cache & 0xfff0000) >> 6; filter->cache = 0; - if (s >= MBFL_WCSPLANE_SUPMIN && s < MBFL_WCSPLANE_SUPMAX) { - CK((*filter->output_function)(s, filter->data)); - } else { /* illegal character */ - CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); - } + CK((*filter->output_function)(s, filter->data)); } else { CK((*filter->output_function)(MBFL_BAD_INPUT, filter->data)); filter->cache = 0; @@ -264,9 +252,7 @@ int mbfl_filt_conv_utf7_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -373,9 +359,7 @@ int mbfl_filt_conv_wchar_utf7(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c b/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c index eb768f9ab2b..473a1f56c13 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf7imap.c @@ -269,9 +269,7 @@ int mbfl_filt_conv_utf7imap_wchar(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -397,9 +395,7 @@ int mbfl_filt_conv_wchar_utf7imap(int c, mbfl_convert_filter *filter) } break; - default: - filter->status = 0; - break; + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; @@ -434,5 +430,6 @@ static int mbfl_filt_conv_wchar_utf7imap_flush(mbfl_convert_filter *filter) CK((*filter->output_function)('-', filter->data)); break; } + return 0; } diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8.c b/ext/mbstring/libmbfl/filters/mbfilter_utf8.c index 524c9c079a1..7c371d2e4d1 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8.c @@ -172,9 +172,8 @@ retry: } } break; - default: - filter->status = 0; - break; + + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c b/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c index c52459dc3ab..14b00945924 100644 --- a/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c +++ b/ext/mbstring/libmbfl/filters/mbfilter_utf8_mobile.c @@ -261,9 +261,8 @@ retry: goto retry; } break; - default: - filter->status = 0; - break; + + EMPTY_SWITCH_DEFAULT_CASE(); } return 0; diff --git a/ext/mbstring/libmbfl/mbfl/mbfilter.c b/ext/mbstring/libmbfl/mbfl/mbfilter.c index 9db80c8895b..a6dfded40a6 100644 --- a/ext/mbstring/libmbfl/mbfl/mbfilter.c +++ b/ext/mbstring/libmbfl/mbfl/mbfilter.c @@ -2480,8 +2480,6 @@ int mbfl_filt_decode_htmlnumericentity_flush(mbfl_convert_filter *filter) (*pc->decoder->filter_function)(mbfl_hexchar_table[d], pc->decoder); } break; - default: - break; } }