From: Bruno Haible Date: Thu, 17 Nov 2016 10:51:55 +0000 (+0100) Subject: Enable Unicode decoder safety unconditionally. X-Git-Tag: v1.0~6547 X-Git-Url: https://gitweb.git.savannah.gnu.org/gitweb/?a=commitdiff_plain;h=a24dbc4ae176ba52547256c636c15c81de17a9ee;p=gnulib.git Enable Unicode decoder safety unconditionally. * lib/unistr.in.h (u32_mbtouc_unsafe): Assume CONFIG_UNICODE_SAFETY. * lib/unistr/u8-mblen.c (u8_mblen): Likewise. * lib/unistr/u8-mbtouc-unsafe.c (u8_mbtouc_unsafe): Likewise. * lib/unistr/u8-mbtouc-unsafe-aux.c (u8_mbtouc_unsafe_aux): Likewise. * lib/unistr/u8-prev.c (u8_prev): Likewise. * lib/unistr/u8-strmblen.c (u8_strmblen): Likewise. * lib/unistr/u8-strmbtouc.c (u8_strmbtouc): Likewise. * lib/unistr/u16-mblen.c (u16_mblen): Likewise. * lib/unistr/u16-mbtouc-unsafe.c (u16_mbtouc_unsafe): Likewise. * lib/unistr/u16-mbtouc-unsafe-aux.c (u16_mbtouc_unsafe_aux): Likewise. * lib/unistr/u16-prev.c (u16_prev): Likewise. * lib/unistr/u16-strmblen.c (u16_strmblen): Likewise. * lib/unistr/u16-strmbtouc.c (u16_strmbtouc): Likewise. * lib/unistr/u32-mblen.c (u32_mblen): Likewise. * lib/unistr/u32-mbtouc-unsafe.c (u32_mbtouc_unsafe): Likewise. * lib/unistr/u32-prev.c (u32_prev): Likewise. * lib/unistr/u32-next.c (u32_next): Likewise. * lib/unistr/u32-strmblen.c (u32_strmblen): Likewise. * lib/unistr/u32-strmbtouc.c (u32_strmbtouc): Likewise. * lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): Likewise. * lib/uniconv/u8-strconv-to-enc.c (u8_strconv_to_encoding): Likewise. * tests/unistr/test-u16-prev.c (check_invalid): Enable the CONFIG_UNICODE_SAFETY tests unconditionally. * tests/unistr/test-u32-mblen.c (main): Likewise. * tests/unistr/test-u32-mbtouc.h (test_function): Likewise. * tests/unistr/test-u32-prev.c (check_invalid): Likewise. * tests/unistr/test-u32-next.c (main): Likewise. * tests/unistr/test-u32-strmblen.c (main): Likewise. * tests/unistr/test-u32-strmbtouc.c (main): Likewise. * tests/unistr/test-u32-mbtouc.c (FULL_SAFETY): Remove macro. * lib/unistr/u8-check.c (u8_check): Remove old dead code. * lib/unistr/u8-mbtouc.c (u8_mbtouc): Likewise. * lib/unistr/u8-mbtouc-aux.c (u8_mbtouc_aux): Likewise. * lib/unistr/u8-mbtoucr.c (u8_mbtoucr): Likewise. * lib/unistr/u8-uctomb.c (u8_uctomb): Likewise. * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. * lib/unistr/u16-check.c (u16_check): Update comment. * NEWS: Mention the changes that callers should be aware of. --- diff --git a/ChangeLog b/ChangeLog index 9582eb5381..7107b0ae6c 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,45 @@ +2016-11-17 Bruno Haible + + Enable Unicode decoder safety unconditionally. + * lib/unistr.in.h (u32_mbtouc_unsafe): Assume CONFIG_UNICODE_SAFETY. + * lib/unistr/u8-mblen.c (u8_mblen): Likewise. + * lib/unistr/u8-mbtouc-unsafe.c (u8_mbtouc_unsafe): Likewise. + * lib/unistr/u8-mbtouc-unsafe-aux.c (u8_mbtouc_unsafe_aux): Likewise. + * lib/unistr/u8-prev.c (u8_prev): Likewise. + * lib/unistr/u8-strmblen.c (u8_strmblen): Likewise. + * lib/unistr/u8-strmbtouc.c (u8_strmbtouc): Likewise. + * lib/unistr/u16-mblen.c (u16_mblen): Likewise. + * lib/unistr/u16-mbtouc-unsafe.c (u16_mbtouc_unsafe): Likewise. + * lib/unistr/u16-mbtouc-unsafe-aux.c (u16_mbtouc_unsafe_aux): Likewise. + * lib/unistr/u16-prev.c (u16_prev): Likewise. + * lib/unistr/u16-strmblen.c (u16_strmblen): Likewise. + * lib/unistr/u16-strmbtouc.c (u16_strmbtouc): Likewise. + * lib/unistr/u32-mblen.c (u32_mblen): Likewise. + * lib/unistr/u32-mbtouc-unsafe.c (u32_mbtouc_unsafe): Likewise. + * lib/unistr/u32-prev.c (u32_prev): Likewise. + * lib/unistr/u32-next.c (u32_next): Likewise. + * lib/unistr/u32-strmblen.c (u32_strmblen): Likewise. + * lib/unistr/u32-strmbtouc.c (u32_strmbtouc): Likewise. + * lib/uniconv/u8-conv-to-enc.c (u8_conv_to_encoding): Likewise. + * lib/uniconv/u8-strconv-to-enc.c (u8_strconv_to_encoding): Likewise. + * tests/unistr/test-u16-prev.c (check_invalid): Enable the + CONFIG_UNICODE_SAFETY tests unconditionally. + * tests/unistr/test-u32-mblen.c (main): Likewise. + * tests/unistr/test-u32-mbtouc.h (test_function): Likewise. + * tests/unistr/test-u32-prev.c (check_invalid): Likewise. + * tests/unistr/test-u32-next.c (main): Likewise. + * tests/unistr/test-u32-strmblen.c (main): Likewise. + * tests/unistr/test-u32-strmbtouc.c (main): Likewise. + * tests/unistr/test-u32-mbtouc.c (FULL_SAFETY): Remove macro. + * lib/unistr/u8-check.c (u8_check): Remove old dead code. + * lib/unistr/u8-mbtouc.c (u8_mbtouc): Likewise. + * lib/unistr/u8-mbtouc-aux.c (u8_mbtouc_aux): Likewise. + * lib/unistr/u8-mbtoucr.c (u8_mbtoucr): Likewise. + * lib/unistr/u8-uctomb.c (u8_uctomb): Likewise. + * lib/unistr/u8-uctomb-aux.c (u8_uctomb_aux): Likewise. + * lib/unistr/u16-check.c (u16_check): Update comment. + * NEWS: Mention the changes that callers should be aware of. + 2016-11-19 Bruno Haible relocatable-prog-wrapper: Fix breakage on Cygwin. diff --git a/NEWS b/NEWS index ac302b59ae..cd30859ddf 100644 --- a/NEWS +++ b/NEWS @@ -3,6 +3,9 @@ Important notes Date Modules Changes +2016-11-17 unistr/u32-strmblen The function u32_strmblen can now return -1. +2016-11-17 unistr/u32-strmbtouc The function u32_strmbtouc can now return -1. + 2015-04-24 acl This module no longer defines file_has_acl. Use the new file-has-acl module for that. Using only the latter module makes for fewer diff --git a/lib/uniconv/u8-conv-to-enc.c b/lib/uniconv/u8-conv-to-enc.c index 1057de70f3..bfd42b1ec8 100644 --- a/lib/uniconv/u8-conv-to-enc.c +++ b/lib/uniconv/u8-conv-to-enc.c @@ -41,13 +41,11 @@ u8_conv_to_encoding (const char *tocode, char *result; /* Conversion from UTF-8 to UTF-8. No need to go through iconv(). */ -#if CONFIG_UNICODE_SAFETY if (u8_check (src, srclen)) { errno = EILSEQ; return NULL; } -#endif /* Memory allocation. */ if (resultbuf != NULL && *lengthp >= srclen) diff --git a/lib/uniconv/u8-strconv-to-enc.c b/lib/uniconv/u8-strconv-to-enc.c index e2c3660fe4..5380306126 100644 --- a/lib/uniconv/u8-strconv-to-enc.c +++ b/lib/uniconv/u8-strconv-to-enc.c @@ -41,13 +41,11 @@ u8_strconv_to_encoding (const uint8_t *string, { /* Conversion from UTF-8 to UTF-8. No need to go through iconv(). */ length = u8_strlen (string) + 1; -#if CONFIG_UNICODE_SAFETY if (u8_check (string, length)) { errno = EILSEQ; return NULL; } -#endif result = (char *) malloc (length); if (result == NULL) { diff --git a/lib/unistr.in.h b/lib/unistr.in.h index 2a64b31d94..f5f5744674 100644 --- a/lib/unistr.in.h +++ b/lib/unistr.in.h @@ -197,15 +197,11 @@ u32_mbtouc_unsafe (ucs4_t *puc, { uint32_t c = *s; -# if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) -# endif *puc = c; -# if CONFIG_UNICODE_SAFETY else /* invalid multibyte character */ *puc = 0xfffd; -# endif return 1; } # endif diff --git a/lib/unistr/u16-check.c b/lib/unistr/u16-check.c index 7bd5d3ee87..8210715ca6 100644 --- a/lib/unistr/u16-check.c +++ b/lib/unistr/u16-check.c @@ -27,7 +27,7 @@ u16_check (const uint16_t *s, size_t n) while (s < s_end) { - /* Keep in sync with unistr.h and utf16-ucs4.c. */ + /* Keep in sync with unistr.h and u16-mbtouc-aux.c. */ uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) diff --git a/lib/unistr/u16-mblen.c b/lib/unistr/u16-mblen.c index 17cb846379..9a42c18c45 100644 --- a/lib/unistr/u16-mblen.c +++ b/lib/unistr/u16-mblen.c @@ -26,24 +26,17 @@ u16_mblen (const uint16_t *s, size_t n) { if (n > 0) { - /* Keep in sync with unistr.h and utf16-ucs4.c. */ + /* Keep in sync with unistr.h and u16-mbtouc-aux.c. */ uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) return (c != 0 ? 1 : 0); -#if CONFIG_UNICODE_SAFETY if (c < 0xdc00) { if (n >= 2 && s[1] >= 0xdc00 && s[1] < 0xe000) return 2; } -#else - { - if (n >= 2) - return 2; - } -#endif } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u16-mbtouc-unsafe-aux.c b/lib/unistr/u16-mbtouc-unsafe-aux.c index 48d2bceb9a..500d8c1e8d 100644 --- a/lib/unistr/u16-mbtouc-unsafe-aux.c +++ b/lib/unistr/u16-mbtouc-unsafe-aux.c @@ -27,15 +27,11 @@ u16_mbtouc_unsafe_aux (ucs4_t *puc, const uint16_t *s, size_t n) { uint16_t c = *s; -#if CONFIG_UNICODE_SAFETY if (c < 0xdc00) -#endif { if (n >= 2) { -#if CONFIG_UNICODE_SAFETY if (s[1] >= 0xdc00 && s[1] < 0xe000) -#endif { *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); return 2; diff --git a/lib/unistr/u16-mbtouc-unsafe.c b/lib/unistr/u16-mbtouc-unsafe.c index 03cf2553f7..c5d7a16920 100644 --- a/lib/unistr/u16-mbtouc-unsafe.c +++ b/lib/unistr/u16-mbtouc-unsafe.c @@ -38,15 +38,11 @@ u16_mbtouc_unsafe (ucs4_t *puc, const uint16_t *s, size_t n) *puc = c; return 1; } -#if CONFIG_UNICODE_SAFETY if (c < 0xdc00) -#endif { if (n >= 2) { -#if CONFIG_UNICODE_SAFETY if (s[1] >= 0xdc00 && s[1] < 0xe000) -#endif { *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); return 2; diff --git a/lib/unistr/u16-prev.c b/lib/unistr/u16-prev.c index 2c3e45a6ef..e9beb736ab 100644 --- a/lib/unistr/u16-prev.c +++ b/lib/unistr/u16-prev.c @@ -33,16 +33,12 @@ u16_prev (ucs4_t *puc, const uint16_t *s, const uint16_t *start) *puc = c_1; return s - 1; } -#if CONFIG_UNICODE_SAFETY if (c_1 >= 0xdc00) -#endif if (s - 1 != start) { uint16_t c_2 = s[-2]; -#if CONFIG_UNICODE_SAFETY if (c_2 >= 0xd800 && c_2 < 0xdc00) -#endif { *puc = 0x10000 + ((c_2 - 0xd800) << 10) + (c_1 - 0xdc00); return s - 2; diff --git a/lib/unistr/u16-strmblen.c b/lib/unistr/u16-strmblen.c index dd507c7158..20acb8c9a1 100644 --- a/lib/unistr/u16-strmblen.c +++ b/lib/unistr/u16-strmblen.c @@ -24,21 +24,16 @@ int u16_strmblen (const uint16_t *s) { - /* Keep in sync with unistr.h and utf16-ucs4.c. */ + /* Keep in sync with unistr.h and u16-mbtouc-aux.c. */ uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) return (c != 0 ? 1 : 0); -#if CONFIG_UNICODE_SAFETY if (c < 0xdc00) { if (s[1] >= 0xdc00 && s[1] < 0xe000) return 2; } -#else - if (s[1] != 0) - return 2; -#endif /* invalid or incomplete multibyte character */ return -1; } diff --git a/lib/unistr/u16-strmbtouc.c b/lib/unistr/u16-strmbtouc.c index f1945fe0db..affa09b6aa 100644 --- a/lib/unistr/u16-strmbtouc.c +++ b/lib/unistr/u16-strmbtouc.c @@ -24,7 +24,7 @@ int u16_strmbtouc (ucs4_t *puc, const uint16_t *s) { - /* Keep in sync with unistr.h and utf16-ucs4.c. */ + /* Keep in sync with unistr.h and u16-mbtouc-aux.c. */ uint16_t c = *s; if (c < 0xd800 || c >= 0xe000) @@ -32,15 +32,9 @@ u16_strmbtouc (ucs4_t *puc, const uint16_t *s) *puc = c; return (c != 0 ? 1 : 0); } -#if CONFIG_UNICODE_SAFETY if (c < 0xdc00) -#endif { -#if CONFIG_UNICODE_SAFETY if (s[1] >= 0xdc00 && s[1] < 0xe000) -#else - if (s[1] != 0) -#endif { *puc = 0x10000 + ((c - 0xd800) << 10) + (s[1] - 0xdc00); return 2; diff --git a/lib/unistr/u32-mblen.c b/lib/unistr/u32-mblen.c index a1d5823fc0..57a88cfac0 100644 --- a/lib/unistr/u32-mblen.c +++ b/lib/unistr/u32-mblen.c @@ -27,9 +27,7 @@ u32_mblen (const uint32_t *s, size_t n) { uint32_t c = *s; -#if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) -#endif return (c != 0 ? 1 : 0); } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u32-mbtouc-unsafe.c b/lib/unistr/u32-mbtouc-unsafe.c index 921b6d1a53..4b8dd3c325 100644 --- a/lib/unistr/u32-mbtouc-unsafe.c +++ b/lib/unistr/u32-mbtouc-unsafe.c @@ -33,15 +33,11 @@ u32_mbtouc_unsafe (ucs4_t *puc, const uint32_t *s, size_t n) { uint32_t c = *s; -#if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) -#endif *puc = c; -#if CONFIG_UNICODE_SAFETY else /* invalid multibyte character */ *puc = 0xfffd; -#endif return 1; } diff --git a/lib/unistr/u32-next.c b/lib/unistr/u32-next.c index cc04a9fa80..d2c7c32d65 100644 --- a/lib/unistr/u32-next.c +++ b/lib/unistr/u32-next.c @@ -30,10 +30,8 @@ u32_next (ucs4_t *puc, const uint32_t *s) return s + count; else { -#if CONFIG_UNICODE_SAFETY if (count < 0) *puc = 0xfffd; -#endif return NULL; } } diff --git a/lib/unistr/u32-prev.c b/lib/unistr/u32-prev.c index ad7f678c75..e44d82a6a2 100644 --- a/lib/unistr/u32-prev.c +++ b/lib/unistr/u32-prev.c @@ -27,9 +27,7 @@ u32_prev (ucs4_t *puc, const uint32_t *s, const uint32_t *start) { uint32_t c_1 = s[-1]; -#if CONFIG_UNICODE_SAFETY if (c_1 < 0xd800 || (c_1 >= 0xe000 && c_1 < 0x110000)) -#endif { *puc = c_1; return s - 1; diff --git a/lib/unistr/u32-strmblen.c b/lib/unistr/u32-strmblen.c index 396a0dd8a6..ea6c334364 100644 --- a/lib/unistr/u32-strmblen.c +++ b/lib/unistr/u32-strmblen.c @@ -25,12 +25,8 @@ u32_strmblen (const uint32_t *s) { uint32_t c = *s; -#if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) -#endif return (c != 0 ? 1 : 0); -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ return -1; -#endif } diff --git a/lib/unistr/u32-strmbtouc.c b/lib/unistr/u32-strmbtouc.c index e3b22b349a..c88c1a516d 100644 --- a/lib/unistr/u32-strmbtouc.c +++ b/lib/unistr/u32-strmbtouc.c @@ -25,15 +25,11 @@ u32_strmbtouc (ucs4_t *puc, const uint32_t *s) { uint32_t c = *s; -#if CONFIG_UNICODE_SAFETY if (c < 0xd800 || (c >= 0xe000 && c < 0x110000)) -#endif { *puc = c; return (c != 0 ? 1 : 0); } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ return -1; -#endif } diff --git a/lib/unistr/u8-check.c b/lib/unistr/u8-check.c index b4f217cd1f..37e7471424 100644 --- a/lib/unistr/u8-check.c +++ b/lib/unistr/u8-check.c @@ -63,40 +63,12 @@ u8_check (const uint8_t *s, size_t n) && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (s[3] ^ 0x80) < 0x40 && (c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif - ) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) { s += 4; continue; } } -#if 0 - else if (c < 0xfc) - { - if (s + 5 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - s += 5; - continue; - } - } - else if (c < 0xfe) - { - if (s + 6 <= s_end - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - s += 6; - continue; - } - } -#endif } /* invalid or incomplete multibyte character */ return s; diff --git a/lib/unistr/u8-mblen.c b/lib/unistr/u8-mblen.c index ba37161330..c88f4c9983 100644 --- a/lib/unistr/u8-mblen.c +++ b/lib/unistr/u8-mblen.c @@ -36,62 +36,26 @@ u8_mblen (const uint8_t *s, size_t n) if (c < 0xe0) { if (n >= 2 -#if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 -#endif - ) + && (s[1] ^ 0x80) < 0x40) return 2; } else if (c < 0xf0) { if (n >= 3 -#if CONFIG_UNICODE_SAFETY && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (c >= 0xe1 || s[1] >= 0xa0) - && (c != 0xed || s[1] < 0xa0) -#endif - ) + && (c != 0xed || s[1] < 0xa0)) return 3; } else if (c < 0xf8) { if (n >= 4 -#if CONFIG_UNICODE_SAFETY && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (s[3] ^ 0x80) < 0x40 && (c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif -#endif - ) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) return 4; } -#if 0 - else if (c < 0xfc) - { - if (n >= 5 -#if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88) -#endif - ) - return 5; - } - else if (c < 0xfe) - { - if (n >= 6 -#if CONFIG_UNICODE_SAFETY - && (s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84) -#endif - ) - return 6; - } -#endif } } /* invalid or incomplete multibyte character */ diff --git a/lib/unistr/u8-mbtouc-aux.c b/lib/unistr/u8-mbtouc-aux.c index d546ae7afa..940f67e05f 100644 --- a/lib/unistr/u8-mbtouc-aux.c +++ b/lib/unistr/u8-mbtouc-aux.c @@ -95,10 +95,7 @@ u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n) if ((s[3] ^ 0x80) < 0x40) { if ((c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif - ) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) { *puc = ((unsigned int) (c & 0x07) << 18) | ((unsigned int) (s[1] ^ 0x80) << 12) @@ -132,105 +129,6 @@ u8_mbtouc_aux (ucs4_t *puc, const uint8_t *s, size_t n) return 3; } } -#if 0 - else if (c < 0xfc) - { - if (n >= 5) - { - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (c >= 0xf9 || s[1] >= 0x88) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } - else if (c < 0xfe) - { - if (n >= 6) - { - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if ((s[5] ^ 0x80) < 0x40) - { - if (c >= 0xfd || s[1] >= 0x84) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 6; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } -#endif } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u8-mbtouc-unsafe-aux.c b/lib/unistr/u8-mbtouc-unsafe-aux.c index 61783e4ba3..4fab7bd975 100644 --- a/lib/unistr/u8-mbtouc-unsafe-aux.c +++ b/lib/unistr/u8-mbtouc-unsafe-aux.c @@ -33,17 +33,13 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) { if (n >= 2) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) -#endif { *puc = ((unsigned int) (c & 0x1f) << 6) | (unsigned int) (s[1] ^ 0x80); return 2; } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ -#endif } else { @@ -56,21 +52,18 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) { if (n >= 3) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) { if ((s[2] ^ 0x80) < 0x40) { if ((c >= 0xe1 || s[1] >= 0xa0) && (c != 0xed || s[1] < 0xa0)) -#endif { *puc = ((unsigned int) (c & 0x0f) << 12) | ((unsigned int) (s[1] ^ 0x80) << 6) | (unsigned int) (s[2] ^ 0x80); return 3; } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ *puc = 0xfffd; return 3; @@ -80,7 +73,6 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) return 2; } /* invalid multibyte character */ -#endif } else { @@ -96,7 +88,6 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) { if (n >= 4) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) { if ((s[2] ^ 0x80) < 0x40) @@ -104,11 +95,8 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) if ((s[3] ^ 0x80) < 0x40) { if ((c >= 0xf1 || s[1] >= 0x90) -#if 1 && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif ) -#endif { *puc = ((unsigned int) (c & 0x07) << 18) | ((unsigned int) (s[1] ^ 0x80) << 12) @@ -116,7 +104,6 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) | (unsigned int) (s[3] ^ 0x80); return 4; } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ *puc = 0xfffd; return 4; @@ -130,7 +117,6 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) return 2; } /* invalid multibyte character */ -#endif } else { @@ -144,113 +130,6 @@ u8_mbtouc_unsafe_aux (ucs4_t *puc, const uint8_t *s, size_t n) return 3; } } -#if 0 - else if (c < 0xfc) - { - if (n >= 5) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (c >= 0xf9 || s[1] >= 0x88) -#endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } -#if CONFIG_UNICODE_SAFETY - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ -#endif - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } - else if (c < 0xfe) - { - if (n >= 6) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if ((s[5] ^ 0x80) < 0x40) - { - if (c >= 0xfd || s[1] >= 0x84) -#endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } -#if CONFIG_UNICODE_SAFETY - /* invalid multibyte character */ - *puc = 0xfffd; - return 6; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ -#endif - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } -#endif } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u8-mbtouc-unsafe.c b/lib/unistr/u8-mbtouc-unsafe.c index b73e99a1b7..477d5557cc 100644 --- a/lib/unistr/u8-mbtouc-unsafe.c +++ b/lib/unistr/u8-mbtouc-unsafe.c @@ -44,17 +44,13 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) { if (n >= 2) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) -#endif { *puc = ((unsigned int) (c & 0x1f) << 6) | (unsigned int) (s[1] ^ 0x80); return 2; } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ -#endif } else { @@ -67,21 +63,18 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) { if (n >= 3) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) { if ((s[2] ^ 0x80) < 0x40) { if ((c >= 0xe1 || s[1] >= 0xa0) && (c != 0xed || s[1] < 0xa0)) -#endif { *puc = ((unsigned int) (c & 0x0f) << 12) | ((unsigned int) (s[1] ^ 0x80) << 6) | (unsigned int) (s[2] ^ 0x80); return 3; } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ *puc = 0xfffd; return 3; @@ -91,7 +84,6 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) return 2; } /* invalid multibyte character */ -#endif } else { @@ -107,7 +99,6 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) { if (n >= 4) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) { if ((s[2] ^ 0x80) < 0x40) @@ -115,11 +106,8 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) if ((s[3] ^ 0x80) < 0x40) { if ((c >= 0xf1 || s[1] >= 0x90) -#if 1 && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif ) -#endif { *puc = ((unsigned int) (c & 0x07) << 18) | ((unsigned int) (s[1] ^ 0x80) << 12) @@ -127,7 +115,6 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) | (unsigned int) (s[3] ^ 0x80); return 4; } -#if CONFIG_UNICODE_SAFETY /* invalid multibyte character */ *puc = 0xfffd; return 4; @@ -141,7 +128,6 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) return 2; } /* invalid multibyte character */ -#endif } else { @@ -155,113 +141,6 @@ u8_mbtouc_unsafe (ucs4_t *puc, const uint8_t *s, size_t n) return 3; } } -#if 0 - else if (c < 0xfc) - { - if (n >= 5) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (c >= 0xf9 || s[1] >= 0x88) -#endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } -#if CONFIG_UNICODE_SAFETY - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ -#endif - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } - else if (c < 0xfe) - { - if (n >= 6) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if ((s[5] ^ 0x80) < 0x40) - { - if (c >= 0xfd || s[1] >= 0x84) -#endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } -#if CONFIG_UNICODE_SAFETY - /* invalid multibyte character */ - *puc = 0xfffd; - return 6; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ -#endif - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } -#endif } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u8-mbtouc.c b/lib/unistr/u8-mbtouc.c index bfb0e4df8a..21e20a5c06 100644 --- a/lib/unistr/u8-mbtouc.c +++ b/lib/unistr/u8-mbtouc.c @@ -105,10 +105,7 @@ u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n) if ((s[3] ^ 0x80) < 0x40) { if ((c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif - ) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) { *puc = ((unsigned int) (c & 0x07) << 18) | ((unsigned int) (s[1] ^ 0x80) << 12) @@ -142,105 +139,6 @@ u8_mbtouc (ucs4_t *puc, const uint8_t *s, size_t n) return 3; } } -#if 0 - else if (c < 0xfc) - { - if (n >= 5) - { - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (c >= 0xf9 || s[1] >= 0x88) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } - else if (c < 0xfe) - { - if (n >= 6) - { - if ((s[1] ^ 0x80) < 0x40) - { - if ((s[2] ^ 0x80) < 0x40) - { - if ((s[3] ^ 0x80) < 0x40) - { - if ((s[4] ^ 0x80) < 0x40) - { - if ((s[5] ^ 0x80) < 0x40) - { - if (c >= 0xfd || s[1] >= 0x84) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 6; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 5; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 4; - } - /* invalid multibyte character */ - *puc = 0xfffd; - return 3; - } - /* invalid multibyte character */ - return 2; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return n; - } - } -#endif } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u8-mbtoucr.c b/lib/unistr/u8-mbtoucr.c index 5fd45b57e9..5586e5fb0c 100644 --- a/lib/unistr/u8-mbtoucr.c +++ b/lib/unistr/u8-mbtoucr.c @@ -92,10 +92,7 @@ u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n) { if ((s[1] ^ 0x80) < 0x40 && (c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif - ) + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) { if (n >= 3) { @@ -138,146 +135,6 @@ u8_mbtoucr (ucs4_t *puc, const uint8_t *s, size_t n) return -2; } } -#if 0 - else if (c < 0xfc) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - if (n >= 5) - { - if ((s[4] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - else if (c < 0xfe) - { - if (n >= 2) - { - if ((s[1] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) - { - if (n >= 3) - { - if ((s[2] ^ 0x80) < 0x40) - { - if (n >= 4) - { - if ((s[3] ^ 0x80) < 0x40) - { - if (n >= 5) - { - if ((s[4] ^ 0x80) < 0x40) - { - if (n >= 6) - { - if ((s[5] ^ 0x80) < 0x40) - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } - /* invalid multibyte character */ - } - else - { - /* incomplete multibyte character */ - *puc = 0xfffd; - return -2; - } - } -#endif } /* invalid multibyte character */ *puc = 0xfffd; diff --git a/lib/unistr/u8-prev.c b/lib/unistr/u8-prev.c index b609acf73b..1abbb41765 100644 --- a/lib/unistr/u8-prev.c +++ b/lib/unistr/u8-prev.c @@ -33,9 +33,7 @@ u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start) *puc = c_1; return s - 1; } -#if CONFIG_UNICODE_SAFETY if ((c_1 ^ 0x80) < 0x40) -#endif if (s - 1 != start) { uint8_t c_2 = s[-2]; @@ -46,38 +44,28 @@ u8_prev (ucs4_t *puc, const uint8_t *s, const uint8_t *start) | (unsigned int) (c_1 ^ 0x80); return s - 2; } -#if CONFIG_UNICODE_SAFETY if ((c_2 ^ 0x80) < 0x40) -#endif if (s - 2 != start) { uint8_t c_3 = s[-3]; if (c_3 >= 0xe0 && c_3 < 0xf0 -#if CONFIG_UNICODE_SAFETY && (c_3 >= 0xe1 || c_2 >= 0xa0) - && (c_3 != 0xed || c_2 < 0xa0) -#endif - ) + && (c_3 != 0xed || c_2 < 0xa0)) { *puc = ((unsigned int) (c_3 & 0x0f) << 12) | ((unsigned int) (c_2 ^ 0x80) << 6) | (unsigned int) (c_1 ^ 0x80); return s - 3; } -#if CONFIG_UNICODE_SAFETY if ((c_3 ^ 0x80) < 0x40) -#endif if (s - 3 != start) { uint8_t c_4 = s[-4]; if (c_4 >= 0xf0 && c_4 < 0xf8 -#if CONFIG_UNICODE_SAFETY && (c_4 >= 0xf1 || c_3 >= 0x90) - && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90)) -#endif - ) + && (c_4 < 0xf4 || (c_4 == 0xf4 && c_3 < 0x90))) { *puc = ((unsigned int) (c_4 & 0x07) << 18) | ((unsigned int) (c_3 ^ 0x80) << 12) diff --git a/lib/unistr/u8-strmblen.c b/lib/unistr/u8-strmblen.c index 49ba0e2202..5cb721416b 100644 --- a/lib/unistr/u8-strmblen.c +++ b/lib/unistr/u8-strmblen.c @@ -33,64 +33,24 @@ u8_strmblen (const uint8_t *s) { if (c < 0xe0) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) -#else - if (s[1] != 0) -#endif return 2; } else if (c < 0xf0) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (c >= 0xe1 || s[1] >= 0xa0) && (c != 0xed || s[1] < 0xa0)) -#else - if (s[1] != 0 && s[2] != 0) -#endif return 3; } else if (c < 0xf8) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (s[3] ^ 0x80) < 0x40 && (c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif - ) -#else - if (s[1] != 0 && s[2] != 0 && s[3] != 0) -#endif + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) return 4; } -#if 0 - else if (c < 0xfc) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) -#else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) -#endif - return 5; - } - else if (c < 0xfe) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) -#else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) -#endif - return 6; - } -#endif } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u8-strmbtouc.c b/lib/unistr/u8-strmbtouc.c index c8094d9b84..746d97287d 100644 --- a/lib/unistr/u8-strmbtouc.c +++ b/lib/unistr/u8-strmbtouc.c @@ -36,11 +36,7 @@ u8_strmbtouc (ucs4_t *puc, const uint8_t *s) { if (c < 0xe0) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40) -#else - if (s[1] != 0) -#endif { *puc = ((unsigned int) (c & 0x1f) << 6) | (unsigned int) (s[1] ^ 0x80); @@ -49,13 +45,9 @@ u8_strmbtouc (ucs4_t *puc, const uint8_t *s) } else if (c < 0xf0) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (c >= 0xe1 || s[1] >= 0xa0) && (c != 0xed || s[1] < 0xa0)) -#else - if (s[1] != 0 && s[2] != 0) -#endif { *puc = ((unsigned int) (c & 0x0f) << 12) | ((unsigned int) (s[1] ^ 0x80) << 6) @@ -65,17 +57,10 @@ u8_strmbtouc (ucs4_t *puc, const uint8_t *s) } else if (c < 0xf8) { -#if CONFIG_UNICODE_SAFETY if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 && (s[3] ^ 0x80) < 0x40 && (c >= 0xf1 || s[1] >= 0x90) -#if 1 - && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90)) -#endif - ) -#else - if (s[1] != 0 && s[2] != 0 && s[3] != 0) -#endif + && (c < 0xf4 || (c == 0xf4 && s[1] < 0x90))) { *puc = ((unsigned int) (c & 0x07) << 18) | ((unsigned int) (s[1] ^ 0x80) << 12) @@ -84,46 +69,6 @@ u8_strmbtouc (ucs4_t *puc, const uint8_t *s) return 4; } } -#if 0 - else if (c < 0xfc) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (c >= 0xf9 || s[1] >= 0x88)) -#else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0) -#endif - { - *puc = ((unsigned int) (c & 0x03) << 24) - | ((unsigned int) (s[1] ^ 0x80) << 18) - | ((unsigned int) (s[2] ^ 0x80) << 12) - | ((unsigned int) (s[3] ^ 0x80) << 6) - | (unsigned int) (s[4] ^ 0x80); - return 5; - } - } - else if (c < 0xfe) - { -#if CONFIG_UNICODE_SAFETY - if ((s[1] ^ 0x80) < 0x40 && (s[2] ^ 0x80) < 0x40 - && (s[3] ^ 0x80) < 0x40 && (s[4] ^ 0x80) < 0x40 - && (s[5] ^ 0x80) < 0x40 - && (c >= 0xfd || s[1] >= 0x84)) -#else - if (s[1] != 0 && s[2] != 0 && s[3] != 0 && s[4] != 0 && s[5] != 0) -#endif - { - *puc = ((unsigned int) (c & 0x01) << 30) - | ((unsigned int) (s[1] ^ 0x80) << 24) - | ((unsigned int) (s[2] ^ 0x80) << 18) - | ((unsigned int) (s[3] ^ 0x80) << 12) - | ((unsigned int) (s[4] ^ 0x80) << 6) - | (unsigned int) (s[5] ^ 0x80); - return 6; - } - } -#endif } /* invalid or incomplete multibyte character */ return -1; diff --git a/lib/unistr/u8-uctomb-aux.c b/lib/unistr/u8-uctomb-aux.c index a41ffcf5a2..aa4dead56c 100644 --- a/lib/unistr/u8-uctomb-aux.c +++ b/lib/unistr/u8-uctomb-aux.c @@ -37,17 +37,8 @@ u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) else return -1; } -#if 0 - else if (uc < 0x200000) - count = 4; - else if (uc < 0x4000000) - count = 5; - else if (uc <= 0x7fffffff) - count = 6; -#else else if (uc < 0x110000) count = 4; -#endif else return -1; @@ -56,10 +47,6 @@ u8_uctomb_aux (uint8_t *s, ucs4_t uc, int n) switch (count) /* note: code falls through cases! */ { -#if 0 - case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; - case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; -#endif case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; /* fallthrough */ case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; diff --git a/lib/unistr/u8-uctomb.c b/lib/unistr/u8-uctomb.c index d62ad0fa10..4db2576eeb 100644 --- a/lib/unistr/u8-uctomb.c +++ b/lib/unistr/u8-uctomb.c @@ -52,17 +52,8 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) else return -1; } -#if 0 - else if (uc < 0x200000) - count = 4; - else if (uc < 0x4000000) - count = 5; - else if (uc <= 0x7fffffff) - count = 6; -#else else if (uc < 0x110000) count = 4; -#endif else return -1; @@ -70,10 +61,6 @@ u8_uctomb (uint8_t *s, ucs4_t uc, int n) { switch (count) /* note: code falls through cases! */ { -#if 0 - case 6: s[5] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x4000000; - case 5: s[4] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x200000; -#endif case 4: s[3] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x10000; case 3: s[2] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0x800; case 2: s[1] = 0x80 | (uc & 0x3f); uc = uc >> 6; uc |= 0xc0; diff --git a/tests/unistr/test-u16-prev.c b/tests/unistr/test-u16-prev.c index a1479d1117..65e9ab3d76 100644 --- a/tests/unistr/test-u16-prev.c +++ b/tests/unistr/test-u16-prev.c @@ -84,7 +84,6 @@ check_invalid (const uint16_t *input, size_t input_length) if (uc != 0xBADFACE) return 2; -#if CONFIG_UNICODE_SAFETY /* Test recognition when preceded by a 1-unit character. */ { uint16_t buf[100]; @@ -121,7 +120,6 @@ check_invalid (const uint16_t *input, size_t input_length) if (uc != 0xBADFACE) return 6; } -#endif return 0; } diff --git a/tests/unistr/test-u32-mblen.c b/tests/unistr/test-u32-mblen.c index a58f2d8e46..e707e21884 100644 --- a/tests/unistr/test-u32-mblen.c +++ b/tests/unistr/test-u32-mblen.c @@ -68,14 +68,12 @@ main () ASSERT (ret == 1); } -#if CONFIG_UNICODE_SAFETY /* Test incomplete/invalid 1-unit input. */ { static const uint32_t input[] = { 0x340000 }; ret = u32_mblen (input, 1); ASSERT (ret == -1); } -#endif return 0; } diff --git a/tests/unistr/test-u32-mbtouc.c b/tests/unistr/test-u32-mbtouc.c index 9cd398edc1..fd5cd53cb6 100644 --- a/tests/unistr/test-u32-mbtouc.c +++ b/tests/unistr/test-u32-mbtouc.c @@ -22,9 +22,6 @@ #include "macros.h" -/* Enable all tests that may be skipped when testing u32_mbtouc_unsafe. */ -#define FULL_SAFETY 1 - #include "test-u32-mbtouc.h" int diff --git a/tests/unistr/test-u32-mbtouc.h b/tests/unistr/test-u32-mbtouc.h index 22d5e0b187..d332125bba 100644 --- a/tests/unistr/test-u32-mbtouc.h +++ b/tests/unistr/test-u32-mbtouc.h @@ -64,7 +64,6 @@ test_function (int (*my_u32_mbtouc) (ucs4_t *, const uint32_t *, size_t)) ASSERT (uc == 0x1D51F); } -#if FULL_SAFETY || CONFIG_UNICODE_SAFETY /* Test incomplete/invalid 1-unit input. */ { static const uint32_t input[] = { 0x340000 }; @@ -73,5 +72,4 @@ test_function (int (*my_u32_mbtouc) (ucs4_t *, const uint32_t *, size_t)) ASSERT (ret == 1); ASSERT (uc == 0xFFFD); } -#endif } diff --git a/tests/unistr/test-u32-next.c b/tests/unistr/test-u32-next.c index b7116b37a7..3b8780498a 100644 --- a/tests/unistr/test-u32-next.c +++ b/tests/unistr/test-u32-next.c @@ -71,7 +71,6 @@ main () ASSERT (uc == 0x1D51F); } -#if CONFIG_UNICODE_SAFETY /* Test incomplete/invalid 1-unit input. */ { static const uint32_t input[] = { 0x340000, 0 }; @@ -80,7 +79,6 @@ main () ASSERT (ret == NULL); ASSERT (uc == 0xFFFD); } -#endif return 0; } diff --git a/tests/unistr/test-u32-prev.c b/tests/unistr/test-u32-prev.c index 5f9cf43ade..cdcda94623 100644 --- a/tests/unistr/test-u32-prev.c +++ b/tests/unistr/test-u32-prev.c @@ -56,7 +56,6 @@ check (const uint32_t *input, size_t input_length, ucs4_t *puc) static int check_invalid (const uint32_t *input, size_t input_length) { -#if CONFIG_UNICODE_SAFETY ucs4_t uc; /* Test recognition when at the beginning of the string. */ @@ -83,7 +82,6 @@ check_invalid (const uint32_t *input, size_t input_length) if (uc != 0xBADFACE) return 4; } -#endif return 0; } diff --git a/tests/unistr/test-u32-strmblen.c b/tests/unistr/test-u32-strmblen.c index ae87b9b6b0..80626b8792 100644 --- a/tests/unistr/test-u32-strmblen.c +++ b/tests/unistr/test-u32-strmblen.c @@ -62,14 +62,12 @@ main () ASSERT (ret == 1); } -#if CONFIG_UNICODE_SAFETY /* Test incomplete/invalid 1-unit input. */ { static const uint32_t input[] = { 0x340000, 0 }; ret = u32_strmblen (input); ASSERT (ret == -1); } -#endif return 0; } diff --git a/tests/unistr/test-u32-strmbtouc.c b/tests/unistr/test-u32-strmbtouc.c index 258c491f6c..fa5311ed92 100644 --- a/tests/unistr/test-u32-strmbtouc.c +++ b/tests/unistr/test-u32-strmbtouc.c @@ -71,7 +71,6 @@ main () ASSERT (uc == 0x1D51F); } -#if CONFIG_UNICODE_SAFETY /* Test incomplete/invalid 1-unit input. */ { static const uint32_t input[] = { 0x340000, 0 }; @@ -80,7 +79,6 @@ main () ASSERT (ret == -1); ASSERT (uc == 0xBADFACE); } -#endif return 0; }