* 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-17 Bruno Haible <bruno@clisp.org>
+
+ 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 <bruno@clisp.org>
relocatable-prog-wrapper: Fix breakage on Cygwin.
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
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)
{
/* 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)
{
{
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
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)
{
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;
{
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;
*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;
*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;
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;
}
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)
*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;
{
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 */
{
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;
}
return s + count;
else
{
-#if CONFIG_UNICODE_SAFETY
if (count < 0)
*puc = 0xfffd;
-#endif
return NULL;
}
}
{
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;
{
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
}
{
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
}
&& (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;
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 */
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)
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;
{
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
{
{
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;
return 2;
}
/* invalid multibyte character */
-#endif
}
else
{
{
if (n >= 4)
{
-#if CONFIG_UNICODE_SAFETY
if ((s[1] ^ 0x80) < 0x40)
{
if ((s[2] ^ 0x80) < 0x40)
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)
| (unsigned int) (s[3] ^ 0x80);
return 4;
}
-#if CONFIG_UNICODE_SAFETY
/* invalid multibyte character */
*puc = 0xfffd;
return 4;
return 2;
}
/* invalid multibyte character */
-#endif
}
else
{
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;
{
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
{
{
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;
return 2;
}
/* invalid multibyte character */
-#endif
}
else
{
{
if (n >= 4)
{
-#if CONFIG_UNICODE_SAFETY
if ((s[1] ^ 0x80) < 0x40)
{
if ((s[2] ^ 0x80) < 0x40)
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)
| (unsigned int) (s[3] ^ 0x80);
return 4;
}
-#if CONFIG_UNICODE_SAFETY
/* invalid multibyte character */
*puc = 0xfffd;
return 4;
return 2;
}
/* invalid multibyte character */
-#endif
}
else
{
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;
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)
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;
{
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)
{
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;
*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];
| (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)
{
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;
{
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);
}
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)
}
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)
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;
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;
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;
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;
{
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;
if (uc != 0xBADFACE)
return 2;
-#if CONFIG_UNICODE_SAFETY
/* Test recognition when preceded by a 1-unit character. */
{
uint16_t buf[100];
if (uc != 0xBADFACE)
return 6;
}
-#endif
return 0;
}
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;
}
#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
ASSERT (uc == 0x1D51F);
}
-#if FULL_SAFETY || CONFIG_UNICODE_SAFETY
/* Test incomplete/invalid 1-unit input. */
{
static const uint32_t input[] = { 0x340000 };
ASSERT (ret == 1);
ASSERT (uc == 0xFFFD);
}
-#endif
}
ASSERT (uc == 0x1D51F);
}
-#if CONFIG_UNICODE_SAFETY
/* Test incomplete/invalid 1-unit input. */
{
static const uint32_t input[] = { 0x340000, 0 };
ASSERT (ret == NULL);
ASSERT (uc == 0xFFFD);
}
-#endif
return 0;
}
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. */
if (uc != 0xBADFACE)
return 4;
}
-#endif
return 0;
}
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;
}
ASSERT (uc == 0x1D51F);
}
-#if CONFIG_UNICODE_SAFETY
/* Test incomplete/invalid 1-unit input. */
{
static const uint32_t input[] = { 0x340000, 0 };
ASSERT (ret == -1);
ASSERT (uc == 0xBADFACE);
}
-#endif
return 0;
}