* iconvdata/8bit-gap.c: Correctly use __builtin_expect.
* iconvdata/ansi_x3.110.c: Likewise.
* iconvdata/big5.c: Likewise.
* iconvdata/euc-cn.c: Likewise.
* iconvdata/euc-jp.c: Likewise.
* iconvdata/euc-kr.c: Likewise.
* iconvdata/gb18030.c: Likewise.
* iconvdata/gbbig5.c: Likewise.
* iconvdata/gbgbk.c: Likewise.
* iconvdata/gbk.c: Likewise.
* iconvdata/ibm930.c: Likewise.
* iconvdata/ibm932.c: Likewise.
* iconvdata/ibm933.c: Likewise.
* iconvdata/ibm935.c: Likewise.
* iconvdata/ibm939.c: Likewise.
* iconvdata/ibm943.c: Likewise.
* iconvdata/iso-2022-cn.c: Likewise.
* iconvdata/iso-2022-kr.c: Likewise.
* iconvdata/iso646.c: Likewise.
* iconvdata/iso8859-1.c: Likewise.
* iconvdata/iso_6937-2.c: Likewise.
* iconvdata/iso_6937.c: Likewise.
* iconvdata/johab.c: Likewise.
* iconvdata/sjis.c: Likewise.
* iconvdata/t.61.c: Likewise.
* iconvdata/uhc.c: Likewise.
* iconvdata/unicode.c: Likewise.
* iconvdata/utf-16.c: Likewise.
* iconv/gconv_simple.c: Likewise. Convert assert() in real error
handling.
2001-08-03 Ulrich Drepper <drepper@redhat.com>
+ * iconvdata/8bit-gap.c: Correctly use __builtin_expect.
+ * iconvdata/ansi_x3.110.c: Likewise.
+ * iconvdata/big5.c: Likewise.
+ * iconvdata/euc-cn.c: Likewise.
+ * iconvdata/euc-jp.c: Likewise.
+ * iconvdata/euc-kr.c: Likewise.
+ * iconvdata/gb18030.c: Likewise.
+ * iconvdata/gbbig5.c: Likewise.
+ * iconvdata/gbgbk.c: Likewise.
+ * iconvdata/gbk.c: Likewise.
+ * iconvdata/ibm930.c: Likewise.
+ * iconvdata/ibm932.c: Likewise.
+ * iconvdata/ibm933.c: Likewise.
+ * iconvdata/ibm935.c: Likewise.
+ * iconvdata/ibm939.c: Likewise.
+ * iconvdata/ibm943.c: Likewise.
+ * iconvdata/iso-2022-cn.c: Likewise.
+ * iconvdata/iso-2022-kr.c: Likewise.
+ * iconvdata/iso646.c: Likewise.
+ * iconvdata/iso8859-1.c: Likewise.
+ * iconvdata/iso_6937-2.c: Likewise.
+ * iconvdata/iso_6937.c: Likewise.
+ * iconvdata/johab.c: Likewise.
+ * iconvdata/sjis.c: Likewise.
+ * iconvdata/t.61.c: Likewise.
+ * iconvdata/uhc.c: Likewise.
+ * iconvdata/unicode.c: Likewise.
+ * iconvdata/utf-16.c: Likewise.
+ * iconv/gconv_simple.c: Likewise. Convert assert() in real error
+ handling.
+
* iconvdata/Makefile: Add rules to build KOI8-T module.
* iconvdata/koi8-t.c: New file.
* iconvdata/gconv-modules: Add entries for KOI8-T.
while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++;
- if (__builtin_expect (cnt, 4) < 4)
+ if (__builtin_expect (cnt < 4, 0))
{
/* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7;
inval = *(const uint32_t *) inptr;
#endif
- if (__builtin_expect (inval, 0) > 0x7fffffff)
+ if (__builtin_expect (inval > 0x7fffffff, 0))
{
/* The value is too large. We don't try transliteration here since
this is not an error because of the lack of possibilities to
for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
{
- if (__builtin_expect (inptr[0], 0) > 0x80)
+ if (__builtin_expect (inptr[0] > 0x80, 0))
{
/* The value is too large. We don't try transliteration here since
this is not an error because of the lack of possibilities to
while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++;
- if (__builtin_expect (cnt, 4) < 4)
+ if (__builtin_expect (cnt < 4, 0))
{
/* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7;
return __GCONV_INCOMPLETE_INPUT;
}
- if (__builtin_expect (((unsigned char *) state->__value.__wchb)[0], 0)
- > 0x80)
+ if (__builtin_expect (((unsigned char *) state->__value.__wchb)[0] > 0x80,
+ 0))
{
/* The value is too large. We don't try transliteration here since
this is not an error because of the lack of possibilities to
while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++;
- if (__builtin_expect (cnt, 4) < 4)
+ if (__builtin_expect (cnt < 4, 0))
{
/* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7;
inval = *(const uint32_t *) inptr;
#endif
- if (__builtin_expect (inval, 0) > 0x7fffffff)
+ if (__builtin_expect (inval > 0x7fffffff, 0))
{
/* The value is too large. We don't try transliteration here since
this is not an error because of the lack of possibilities to
for (cnt = 0; cnt < n_convert; ++cnt, inptr += 4)
{
- if (__builtin_expect (inptr[3], 0) > 0x80)
+ if (__builtin_expect (inptr[3] > 0x80, 0))
{
/* The value is too large. We don't try transliteration here since
this is not an error because of the lack of possibilities to
while (*inptrp < inend && cnt < 4)
state->__value.__wchb[cnt++] = *(*inptrp)++;
- if (__builtin_expect (cnt, 4) < 4)
+ if (__builtin_expect (cnt < 4, 0))
{
/* Still not enough bytes. Store the ones in the input buffer. */
state->__count &= ~7;
return __GCONV_INCOMPLETE_INPUT;
}
- if (__builtin_expect (((unsigned char *) state->__value.__wchb)[3], 0)
- > 0x80)
+ if (__builtin_expect (((unsigned char *) state->__value.__wchb)[3] > 0x80,
+ 0))
{
/* The value is too large. We don't try transliteration here since
this is not an error because of the lack of possibilities to
#define LOOPFCT FROM_LOOP
#define BODY \
{ \
- if (__builtin_expect (*inptr, 0) > '\x7f') \
+ if (__builtin_expect (*inptr > '\x7f', 0)) \
{ \
/* The value is too large. We don't try transliteration here since \
this is not an error because of the lack of possibilities to \
#define LOOPFCT FROM_LOOP
#define BODY \
{ \
- if (__builtin_expect (*((const uint32_t *) inptr), 0) > 0x7f) \
+ if (__builtin_expect (*((const uint32_t *) inptr) > 0x7f, 0)) \
{ \
UNICODE_TAG_HANDLER (*((const uint32_t *) inptr), 4); \
STANDARD_ERR_HANDLER (4); \
{ \
uint32_t wc = *((const uint32_t *) inptr); \
\
- /* Since we control every character we read this cannot happen. */ \
- assert (wc <= 0x7fffffff); \
- \
if (wc < 0x80) \
/* It's an one byte sequence. */ \
*outptr++ = (unsigned char) wc; \
- else \
+ else if (__builtin_expect (wc <= 0x7fffffff, 1)) \
{ \
size_t step; \
char *start; \
} \
while (--step > 0); \
start[0] |= wc; \
+ } \
+ else \
+ { \
+ STANDARD_ERR_HANDLER (4); \
} \
\
inptr += 4; \
}
+#define LOOP_NEED_FLAGS
#include <iconv/loop.c>
#include <iconv/skeleton.c>
cnt = 2; \
ch &= 0x1f; \
} \
- else if (__builtin_expect (ch & 0xf0, 0xe0) == 0xe0) \
+ else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1)) \
{ \
/* We expect three bytes. */ \
cnt = 3; \
ch &= 0x0f; \
} \
- else if (__builtin_expect (ch & 0xf8, 0xf0) == 0xf0) \
+ else if (__builtin_expect ((ch & 0xf8) == 0xf0, 1)) \
{ \
/* We expect four bytes. */ \
cnt = 4; \
ch &= 0x07; \
} \
- else if (__builtin_expect (ch & 0xfc, 0xf8) == 0xf8) \
+ else if (__builtin_expect ((ch & 0xfc) == 0xf8, 1)) \
{ \
/* We expect five bytes. */ \
cnt = 5; \
ch &= 0x03; \
} \
- else if (__builtin_expect (ch & 0xfe, 0xfc) == 0xfc) \
+ else if (__builtin_expect ((ch & 0xfe) == 0xfc, 1)) \
{ \
/* We expect six bytes. */ \
cnt = 6; \
cnt = 2; \
ch &= 0x1f; \
} \
- else if (__builtin_expect (ch & 0xf0, 0xe0) == 0xe0) \
+ else if (__builtin_expect ((ch & 0xf0) == 0xe0, 1)) \
{ \
/* We expect three bytes. */ \
cnt = 3; \
ch &= 0x0f; \
} \
- else if (__builtin_expect (ch & 0xf8, 0xf0) == 0xf0) \
+ else if (__builtin_expect ((ch & 0xf8) == 0xf0, 1)) \
{ \
/* We expect four bytes. */ \
cnt = 4; \
ch &= 0x07; \
} \
- else if (__builtin_expect (ch & 0xfc, 0xf8) == 0xf8) \
+ else if (__builtin_expect ((ch & 0xfc) == 0xf8, 1)) \
{ \
/* We expect five bytes. */ \
cnt = 5; \
bytebuf[0] = 0xc0; \
ntotal = 2; \
} \
- else if (__builtin_expect (state->__value.__wch, 0) <= 0xffff) \
+ else if (__builtin_expect (state->__value.__wch <= 0xffff, 1)) \
{ \
bytebuf[0] = 0xe0; \
ntotal = 3; \
} \
- else if (__builtin_expect (state->__value.__wch, 0) <= 0x1fffff) \
+ else if (__builtin_expect (state->__value.__wch < 0x1fffff, 1)) \
{ \
bytebuf[0] = 0xf0; \
ntotal = 4; \
} \
- else if (__builtin_expect (state->__value.__wch, 0) <= 0x3ffffff) \
+ else if (__builtin_expect (state->__value.__wch < 0x3ffffff, 1)) \
{ \
bytebuf[0] = 0xf8; \
ntotal = 5; \
{ \
uint32_t val = *((const uint32_t *) inptr); \
\
- if (__builtin_expect (val, 0) >= 0x10000) \
+ if (__builtin_expect (val >= 0x10000, 0)) \
{ \
UNICODE_TAG_HANDLER (val, 4); \
STANDARD_ERR_HANDLER (4); \
#define BODY \
{ \
uint32_t val = *((const uint32_t *) inptr); \
- if (__builtin_expect (val, 0) >= 0x10000) \
+ if (__builtin_expect (val >= 0x10000, 0)) \
{ \
UNICODE_TAG_HANDLER (val, 4); \
STANDARD_ERR_HANDLER (4); \
uint32_t ch = get32 (inptr); \
unsigned char res; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
rp = NULL; \
uint32_t ch = *inptr; \
int incr; \
\
- if (__builtin_expect (ch, 0x00) >= 0xc1 && ch <= 0xcf) \
+ if (__builtin_expect (ch >= 0xc1, 0) && ch <= 0xcf) \
{ \
/* Composed character. First test whether the next character \
is also available. */ \
\
ch2 = inptr[1]; \
\
- if (__builtin_expect (ch2, 0x20) < 0x20 \
- || __builtin_expect (ch2, 0x7f) >= 0x80) \
+ if (__builtin_expect (ch2 < 0x20, 0) \
+ || __builtin_expect (ch2 >= 0x80, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
uint32_t ch = get32 (inptr); \
const char *cp; \
\
- if ((size_t) __builtin_expect (ch, 0) \
- >= sizeof (from_ucs4) / sizeof (from_ucs4[0])) \
+ if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \
+ 0)) \
{ \
if (ch == 0x2c7) \
cp = "\xcf\x20"; \
/* See whether the second byte is in the correct range. */ \
if (ch2 >= 0x40 && ch2 <= 0x7e) \
idx += ch2 - 0x40; \
- else if (__builtin_expect (ch2, 0xa1) >= 0xa1 \
- && __builtin_expect (ch2, 0xa1) <= 0xfe) \
+ else if (__builtin_expect (ch2 >= 0xa1, 1) \
+ && __builtin_expect (ch2 <= 0xfe, 1)) \
idx += 0x3f + (ch2 - 0xa1); \
else \
{ \
uint32_t ch = get32 (inptr); \
const char *cp; \
\
- if ((size_t) __builtin_expect (ch, 0) \
- >= sizeof (from_ucs4_tab1) / sizeof (from_ucs4_tab1[0])) \
+ if (__builtin_expect (ch >= (sizeof (from_ucs4_tab1) \
+ / sizeof (from_ucs4_tab1[0])), 0)) \
switch (ch) \
{ \
case 0x2c7 ... 0x2d9: \
if (ch <= 0x7f) \
++inptr; \
else \
- if ((__builtin_expect (ch, 0xa1) <= 0xa0 && ch != 0x8e && ch != 0x8f) \
- || __builtin_expect (ch, 0xfe) > 0xfe) \
+ if ((__builtin_expect (ch <= 0xa0, 0) && ch != 0x8e && ch != 0x8f) \
+ || __builtin_expect (ch > 0xfe, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
ch = inptr[1]; \
\
/* All second bytes of a multibyte character must be >= 0xa1. */ \
- if (__builtin_expect (ch, 0xa1) < 0xa1) \
+ if (__builtin_expect (ch < 0xa1, 0)) \
{ \
if (! ignore_errors_p ()) \
{ \
ch2 = inptr[1]; \
\
/* All second bytes of a multibyte character must be >= 0xa1. */ \
- if (__builtin_expect (ch2, 0xa1) < 0xa1) \
+ if (__builtin_expect (ch2 < 0xa1, 0)) \
{ \
/* This is an illegal character. */ \
if (! ignore_errors_p ()) \
++inptr; \
/* 0xfe(->0x7e : row 94) and 0xc9(->0x59 : row 41) are \
user-defined areas. */ \
- else if (__builtin_expect (ch, 0xa1) == 0xa0 \
- || __builtin_expect (ch, 0xa1) > 0xfe \
- || __builtin_expect (ch, 0xa1) == 0xc9) \
+ else if (__builtin_expect (ch == 0xa0, 0) \
+ || __builtin_expect (ch > 0xfe, 0) \
+ || __builtin_expect (ch == 0xc9, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
\
inptr += 4; \
} \
- else if (__builtin_expect (ch2, 0x40) >= 0x40) \
+ else if (__builtin_expect (ch2 >= 0x40, 1)) \
{ \
/* A two-byte character */ \
idx = (ch - 0x81) * 192 + (ch2 - 0x40); \
/* Mapping tables from GB2312 to BIG5 and vice versa.
- Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
* This module does convertions between gb2312 and big5 encodings.
* It is necessary because gb2312 encoding use simplified chinese,
* while big5 use traditional one. Often times both the simplified
- * version of a chinese character and its traditional counterpart
+ * version of a chinese character and its traditional counterpart
* are presented in unicode and have distinctive code values. So
* an indirect method through UCS4 (GB2312 <=> UCS4 <=> BIG5) will
* not do the work correctly.
ch = inptr[1]; \
\
/* All second bytes of a multibyte character must be >= 0xa1. */ \
- if (__builtin_expect (ch, 0xa1) < 0xa1) \
+ if (__builtin_expect (ch < 0xa1, 0)) \
{ \
/* This is an illegal character. */ \
if (! ignore_errors_p ()) \
/* See if the second byte is in the correct range. */ \
if (ch >= 0x40 && ch <= 0x7e) \
idx += ch - 0x40; \
- else if (__builtin_expect (ch, 0xa1) >= 0xa1 \
- && __builtin_expect (ch, 0xa1) <= 0xfe) \
+ else if (__builtin_expect (ch >= 0xa1, 1) \
+ && __builtin_expect (ch <= 0xfe, 1)) \
idx += 0x3f + (ch - 0xa1); \
else \
{ \
/* Mapping tables from GBK to GB2312 and vice versa.
- Copyright (C) 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of the GNU C Library.
Contributed by Ulrich Drepper <drepper@cygnus.com>, 1999.
ch = 0xa1aa; \
\
/* Now determine whether the character is valid. */ \
- if (__builtin_expect (ch, 0xa1a1) < 0xa1a1 \
- || __builtin_expect (ch, 0xa1a1) > 0xf7fe \
- || __builtin_expect (inptr[1], 0xa1) < 0xa1 \
+ if (__builtin_expect (ch < 0xa1a1, 0) \
+ || __builtin_expect (ch > 0xf7fe, 0) \
+ || __builtin_expect (inptr[1] < 0xa1, 0) \
/* Now test the exceptions. */ \
- || (__builtin_expect (ch, 0xa1a1) >= 0xa2a1 \
- && __builtin_expect (ch, 0xa1a1) <= 0xa2aa) \
- || (__builtin_expect (ch, 0xa1a1) >= 0xa6e0 \
- && __builtin_expect (ch, 0xa1a1) <= 0xa6f5) \
- || (__builtin_expect (ch, 0xa1a1) >= 0xa8bb \
- && __builtin_expect (ch, 0xa1a1) <= 0xa8c0)) \
+ || (__builtin_expect (ch >= 0xa2a1, 0) \
+ && __builtin_expect (ch <= 0xa2aa, 0)) \
+ || (__builtin_expect (ch >= 0xa6e0, 0) \
+ && __builtin_expect (ch <= 0xa6f5, 0)) \
+ || (__builtin_expect (ch >= 0xa8bb, 0) \
+ && __builtin_expect (ch <= 0xa8c0, 0))) \
{ \
/* One of the characters we cannot map. */ \
STANDARD_ERR_HANDLER (2); \
if (ch <= 0x7f) \
++inptr; \
else \
- if (__builtin_expect (ch, 0x81) <= 0x80 \
- || __builtin_expect (ch, 0x81) > 0xfe) \
+ if (__builtin_expect (ch <= 0x80, 0) \
+ || __builtin_expect (ch > 0xfe, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
\
/* All second bytes of a multibyte character must be >= 0x40, and \
the __gbk_to_ucs table only covers the range up to 0xfe 0xa0. */ \
- if (__builtin_expect (ch2, 0x41) < 0x40 \
+ if (__builtin_expect (ch2 < 0x40, 0) \
|| (__builtin_expect (ch, 0x81) == 0xfe && ch2 > 0xa0)) \
{ \
/* This is an illegal character. */ \
const struct gap *rp2 = __ucs4_to_ibm930db_idx; \
const char *cp; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
\
{ \
if (curcs == sb) \
{ \
- if (__builtin_expect (outptr+1 > outend, 0)) \
+ if (__builtin_expect (outptr + 1 > outend, 0)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
#endif
#define FROM 0
-#define TO 1
+#define TO 1
/* Definitions used in the body of the `gconv' function. */
#define CHARSET_NAME "IBM932//"
uint32_t ch = *inptr; \
uint32_t res; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
rp1 = NULL; \
rp2 = NULL; \
uint32_t high; \
uint16_t pccode; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
rp = NULL; \
const struct gap *rp2 = __ucs4_to_ibm933db_idx; \
const char *cp; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
\
{ \
if (curcs == sb) \
{ \
- if (__builtin_expect (outptr+1 > outend, 0)) \
+ if (__builtin_expect (outptr + 1 > outend, 0)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
const struct gap *rp2 = __ucs4_to_ibm935db_idx; \
const char *cp; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
\
{ \
if (curcs == sb) \
{ \
- if (__builtin_expect (outptr+1 > outend, 0)) \
+ if (__builtin_expect (outptr + 1 > outend, 0)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
const struct gap *rp2 = __ucs4_to_ibm939db_idx; \
const char *cp; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
rp1 = NULL; \
{ \
if (curcs == sb) \
{ \
- if (__builtin_expect (outptr+1 > outend, 0)) \
+ if (__builtin_expect (outptr + 1 > outend, 0)) \
{ \
result = __GCONV_FULL_OUTPUT; \
break; \
#endif
#define FROM 0
-#define TO 1
+#define TO 1
/* Definitions used in the body of the `gconv' function. */
#define CHARSET_NAME "IBM943//"
uint32_t ch = *inptr; \
uint32_t res; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
rp1 = NULL; \
rp2 = NULL; \
uint32_t high; \
uint16_t pccode; \
\
- if (__builtin_expect (ch, 0) >= 0xffff) \
+ if (__builtin_expect (ch >= 0xffff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
rp = NULL; \
uint32_t ch = *inptr; \
\
/* This is a 7bit character set, disallow all 8bit characters. */ \
- if (__builtin_expect (ch, 0) > 0x7f) \
+ if (__builtin_expect (ch >= 0x7f, 0)) \
{ \
if (! ignore_errors_p ()) \
{ \
uint32_t ch = *inptr; \
\
/* This is a 7bit character set, disallow all 8bit characters. */ \
- if (__builtin_expect (ch, 0) > 0x7f) \
+ if (__builtin_expect (ch > 0x7f, 0)) \
{ \
if (! ignore_errors_p ()) \
{ \
ch = 0x5d; \
break; \
default: \
- if (__builtin_expect (ch, 0) > 0x7f) \
+ if (__builtin_expect (ch > 0x7f, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
failure = __GCONV_ILLEGAL_INPUT; \
#define BODY \
{ \
uint32_t ch = *((const uint32_t *) inptr); \
- if (__builtin_expect (ch, 0) > 0xff) \
+ if (__builtin_expect (ch > 0xff, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
\
{ \
uint32_t ch = *inptr; \
\
- if (__builtin_expect (ch, 0) >= 0xc1 && ch <= 0xcf) \
+ if (__builtin_expect (ch >= 0xc1, 0) && ch <= 0xcf) \
{ \
/* Composed character. First test whether the next character \
is also available. */ \
\
ch2 = inptr[1]; \
\
- if (__builtin_expect (ch2, 0) < 0x20 \
- || __builtin_expect (ch2, 0) >= 0x80) \
+ if (__builtin_expect (ch2 < 0x20, 0) \
+ || __builtin_expect (ch2 >= 0x80, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
uint32_t ch = get32 (inptr); \
const char *cp; \
\
- if ((size_t) __builtin_expect (ch, 0) \
- >= sizeof (from_ucs4) / sizeof (from_ucs4[0])) \
+ if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \
+ 0)) \
{ \
switch (ch) \
{ \
{ \
uint32_t ch = *inptr; \
\
- if (__builtin_expect (ch, 0) >= 0xc1 && ch <= 0xcf) \
+ if (__builtin_expect (ch >= 0xc1, 0) && ch <= 0xcf) \
{ \
/* Composed character. First test whether the next character \
is also available. */ \
\
ch2 = inptr[1]; \
\
- if (__builtin_expect (ch2, 0) < 0x20 \
- || __builtin_expect (ch2, 0) >= 0x80) \
+ if (__builtin_expect (ch2 < 0x20, 0) \
+ || __builtin_expect (ch2 >= 0x80, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
uint32_t ch = get32 (inptr); \
const char *cp; \
\
- if ((size_t) __builtin_expect (ch, 0) \
- >= sizeof (from_ucs4) / sizeof (from_ucs4[0])) \
+ if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \
+ 0)) \
{ \
int fail = 0; \
switch (ch) \
0xd831-0xd87e and 0xd891-0xd8fe are user-defined area */ \
else \
{ \
- if (__builtin_expect (ch, 0) > 0xf9 \
- || __builtin_expect (ch, 0) == 0xdf \
- || (__builtin_expect (ch, 0) > 0x7e && ch < 0x84) \
- || (__builtin_expect (ch, 0) > 0xd3 && ch < 0xd9)) \
+ if (__builtin_expect (ch > 0xf9, 0) \
+ || __builtin_expect (ch == 0xdf, 0) \
+ || (__builtin_expect (ch > 0x7e, 0) && ch < 0x84) \
+ || (__builtin_expect (ch > 0xd3, 0) && ch < 0xd9)) \
{ \
/* These are illegal. */ \
if (! ignore_errors_p ()) \
\
ch2 = inptr[1]; \
idx = ch * 256 + ch2; \
- if (__builtin_expect (ch, 0) <= 0xd3) \
+ if (__builtin_expect (ch <= 0xd3, 1)) \
{ \
/* Hangul */ \
uint_fast32_t i, m, f; \
else if (i == 0 && m > 0 && f == 0) \
ch = 0x314e + m; /* 0x314f + m - 1 */ \
else if (__builtin_expect (i | m, 0) == 0 \
- && __builtin_expect (f, 1) > 0) \
+ && __builtin_expect (f > 0, 1)) \
ch = final_to_ucs[f - 1]; /* round trip?? */ \
else \
{ \
} \
else \
{ \
- if (__builtin_expect (ch2, 0x31) < 0x31 \
- || (__builtin_expect (ch2, 0x7e) > 0x7e && ch2 < 0x91) \
+ if (__builtin_expect (ch2 < 0x31, 0) \
+ || (__builtin_expect (ch2 > 0x7e, 0) && ch2 < 0x91) \
|| __builtin_expect (ch2, 0) == 0xff \
|| (__builtin_expect (ch, 0) == 0xd9 && ch2 > 0xe5) \
|| (__builtin_expect (ch, 0) == 0xda \
ch = halfkana_to_ucs4[ch - 0xa1]; \
++inptr; \
} \
- else if (__builtin_expect (ch, 0) > 0xea \
+ else if (__builtin_expect (ch > 0xea, 0) \
|| __builtin_expect (ch, 0) == 0xa0 \
- || __builtin_expect (ch, 0x81) <= 0x80) \
+ || __builtin_expect (ch <= 0x80, 0)) \
{ \
/* These are illegal. */ \
if (! ignore_errors_p ()) \
ch2 = inptr[1]; \
idx = ch * 256 + ch2; \
if (__builtin_expect (ch2 < 0x40, 0) \
- || (__builtin_expect (idx, 0x8140) > 0x84be && idx < 0x889f) \
- || (__builtin_expect (idx, 0x8140) > 0x88fc && idx < 0x8940) \
- || (__builtin_expect (idx, 0x8140) > 0x9ffc && idx < 0xe040) \
- || __builtin_expect (idx, 0x8140) > 0xeaa4) \
+ || (__builtin_expect (idx > 0x84be, 0) && idx < 0x889f) \
+ || (__builtin_expect (idx > 0x88fc, 0) && idx < 0x8940) \
+ || (__builtin_expect (idx > 0x9ffc, 0) && idx < 0xe040) \
+ || __builtin_expect (idx > 0xeaa4, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
cp = from_ucs4_greek[ch - 0x391]; \
else if (ch >= 0x2010 && ch <= 0x9fa0) \
cp = from_ucs4_cjk[ch - 0x02010]; \
- else if (__builtin_expect (ch, 0xff01) >= 0xff01 \
- && __builtin_expect (ch, 0xff01) <= 0xffef) \
+ else if (__builtin_expect (ch >= 0xff01, 1) \
+ && __builtin_expect (ch <= 0xffef, 1)) \
cp = from_ucs4_extra[ch - 0xff00]; \
else \
{ \
uint32_t ch = *inptr; \
int increment = 1; \
\
- if (__builtin_expect (ch, 0x20) >= 0xc1 && ch <= 0xcf) \
+ if (__builtin_expect (ch >= 0xc1, 0) && ch <= 0xcf) \
{ \
/* Composed character. First test whether the next character \
is also available. */ \
\
ch2 = inptr[1]; \
\
- if (__builtin_expect (ch2, 0x20) < 0x20 \
- || __builtin_expect (ch2, 0x20) >= 0x80) \
+ if (__builtin_expect (ch2 < 0x20, 0) \
+ || __builtin_expect (ch2 >= 0x80, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
uint32_t ch = get32 (inptr); \
const char *cp; \
\
- if ((size_t) __builtin_expect (ch, 0) \
- >= sizeof (from_ucs4) / sizeof (from_ucs4[0])) \
+ if (__builtin_expect (ch >= sizeof (from_ucs4) / sizeof (from_ucs4[0]), \
+ 0)) \
{ \
if (__builtin_expect (ch, 0) == 0x2126) \
cp = "\xe0"; \
else if (__builtin_expect (ch, 0) == 0x2c7) \
cp = "\xcf\x20"; \
- else if (__builtin_expect (ch, 0x2d8) < 0x2d8 \
- || __builtin_expect (ch, 0x2d8) > 0x2dd \
- || __builtin_expect (ch, 0x2d8) == 0x02dc) \
+ else if (__builtin_expect (ch < 0x2d8, 0) \
+ || __builtin_expect (ch > 0x2dd, 0) \
+ || __builtin_expect (ch == 0x2dc, 0)) \
{ \
UNICODE_TAG_HANDLER (ch, 4); \
\
*/ \
if (ch <= 0x7f) \
++inptr; \
- else if (__builtin_expect (ch, 0x81) <= 0x80 \
- || __builtin_expect (ch, 0x81) >= 0xfe \
- || __builtin_expect (ch, 0x81) == 0xc9) \
+ else if (__builtin_expect (ch <= 0x80, 0) \
+ || __builtin_expect (ch >= 0xfe, 0) \
+ || __builtin_expect (ch == 0xc9, 0)) \
{ \
/* This is illegal. */ \
if (! ignore_errors_p ()) \
\
if (ch < 0xa1 || ch2 < 0xa1) \
{ \
- if (__builtin_expect (ch, 0xc5) > 0xc6 \
- || __builtin_expect (ch2, 0x41) < 0x41 \
- || __builtin_expect (ch2, 0x41) > 0xfe \
- || (__builtin_expect (ch2, 0x41) > 0x5a && ch2 < 0x61) \
- || (__builtin_expect (ch2, 0x41) > 0x7a && ch2 < 0x81) \
- || (__builtin_expect (ch, 0xc5) == 0xc6 && ch2 > 0x52)) \
+ if (__builtin_expect (ch > 0xc6, 0) \
+ || __builtin_expect (ch2 < 0x41, 0) \
+ || __builtin_expect (ch2 > 0xfe, 0) \
+ || (__builtin_expect (ch2 > 0x5a, 0) && ch2 < 0x61) \
+ || (__builtin_expect (ch2 > 0x7a, 0) && ch2 < 0x81) \
+ || (__builtin_expect (ch == 0xc6, 0) && ch2 > 0x52)) \
{ \
/* This is not legal. */ \
if (! ignore_errors_p ()) \
{ \
uint32_t c = get32 (inptr); \
\
- if (__builtin_expect (c, 0) >= 0x10000) \
+ if (__builtin_expect (c >= 0x10000, 0)) \
{ \
UNICODE_TAG_HANDLER (c, 4); \
STANDARD_ERR_HANDLER (4); \
\
if (swap) \
{ \
- if (__builtin_expect (c, 0) >= 0x10000) \
+ if (__builtin_expect (c >= 0x10000, 0)) \
{ \
- if (__builtin_expect (c, 0) >= 0x110000) \
+ if (__builtin_expect (c >= 0x110000, 0)) \
{ \
STANDARD_ERR_HANDLER (4); \
} \
} \
else \
{ \
- if (__builtin_expect (c, 0) >= 0x10000) \
+ if (__builtin_expect (c >= 0x10000, 0)) \
{ \
- if (__builtin_expect (c, 0) >= 0x110000) \
+ if (__builtin_expect (c >= 0x110000, 0)) \
{ \
STANDARD_ERR_HANDLER (4); \
} \
{ \
u1 = bswap_16 (u1); \
\
- if (__builtin_expect (u1, 0) < 0xd800 || u1 > 0xdfff) \
+ if (__builtin_expect (u1 < 0xd800, 1) || u1 > 0xdfff) \
{ \
/* No surrogate. */ \
put32 (outptr, u1); \
\
inptr += 2; \
u2 = bswap_16 (get16 (inptr)); \
- if (__builtin_expect (u2, 0xdc00) < 0xdc00 \
- || __builtin_expect (u2, 0xdc00) >= 0xdfff) \
+ if (__builtin_expect (u2 < 0xdc00, 0) \
+ || __builtin_expect (u2 == 0xdfff, 0)) \
{ \
/* This is no valid second word for a surrogate. */ \
if (! ignore_errors_p ()) \
} \
else \
{ \
- if (__builtin_expect (u1, 0) < 0xd800 || u1 > 0xdfff) \
+ if (__builtin_expect (u1 < 0xd800, 1) || u1 > 0xdfff) \
{ \
/* No surrogate. */ \
put32 (outptr, u1); \
\
inptr += 2; \
u2 = get16 (inptr); \
- if (__builtin_expect (u2, 0xdc00) < 0xdc00 \
- || __builtin_expect (u2, 0xdc00) >= 0xdfff) \
+ if (__builtin_expect (u2 < 0xdc00, 0) \
+ || __builtin_expect (u2 >= 0xdfff, 0)) \
{ \
/* This is no valid second word for a surrogate. */ \
if (! ignore_errors_p ()) \
tst_wctype tst_wcwidth
tests = $(locale_test_suite) tst-digits tst-setlocale bug-iconv-trans \
- tst-leaks
+ tst-leaks tst-mbswcs6
ifeq (yes,$(build-shared))
ifneq (no,$(PERL))
tests: $(objpfx)mtrace-tst-leaks
$(addprefix $(objpfx),$(CTYPE_FILES))
$(SHELL) -e $< $(common-objpfx) '$(built-program-cmd)'
$(objpfx)tst-digits.out: $(objpfx)tst-locale.out
+$(objpfx)tst-mbswcs6.out: $(addprefix $(objpfx),$(CTYPE_FILES))
endif
include SUPPORTED
tst_wctype-ENV = $(TEST_MBWC_ENV)
tst_wcwidth-ENV = $(TEST_MBWC_ENV)
tst-digits-ENV = $(TEST_MBWC_ENV)
+tst-mbswcs6-ENV = $(TEST_MBWC_ENV)
tst-setlocale-ENV = LOCPATH=$(common-objpfx)localedata LC_ALL=ja_JP.EUC-JP
--- /dev/null
+/* Test for invalid input to wcrtomb.
+ Copyright (C) 2001 Free Software Foundation, Inc.
+ This file is part of the GNU C Library.
+ Contributed by Ulrich Drepper <drepper@redhat.com>, 2001.
+
+ The GNU C Library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 2.1 of the License, or (at your option) any later version.
+
+ The GNU C Library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General Public
+ License along with the GNU C Library; if not, write to the Free
+ Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
+ 02111-1307 USA. */
+
+#include <errno.h>
+#include <locale.h>
+#include <stdio.h>
+#include <string.h>
+#include <wchar.h>
+
+
+static int
+do_test (const char *loc)
+{
+ char buf[100];
+ size_t n;
+ mbstate_t state;
+ const char *nloc;
+ int res;
+
+ nloc = setlocale (LC_ALL, loc);
+ if (nloc == NULL)
+ {
+ printf ("could not set locale \"%s\"\n", loc);
+ return 1;
+ }
+ printf ("new locale: %s\n", nloc);
+
+ memset (&state, '\0', sizeof (state));
+ errno = 0;
+ n = wcrtomb (buf, (wchar_t) -15l, &state);
+
+ printf ("n = %zd, errno = %d (%s)\n", n, errno, strerror (errno));
+
+ res = n != (size_t) -1 || errno != EILSEQ;
+ if (res)
+ puts ("*** FAIL");
+ putchar ('\n');
+
+ return res;
+}
+
+
+int
+main (void)
+{
+ int res;
+
+ res = do_test ("C");
+ res |= do_test ("de_DE.ISO-8859-1");
+ res |= do_test ("de_DE.UTF-8");
+ res |= do_test ("en_US.ANSI_X3.4-1968");
+ res |= do_test ("ja_JP.EUC-JP");
+ res |= do_test ("hr_HR.ISO-8859-2");
+ //res |= do_test ("ru_RU.KOI8-R");
+
+ return res;
+}