return ((unsigned int)c == (unsigned char)c);
}
+void mbtowc_reset(void)
+{
+ IGNORE_CALL_RESULT(mbtowc(NULL, NULL, 0));
+}
+
+void wctomb_reset(void)
+{
+ IGNORE_CALL_RESULT(wctomb(NULL, 0));
+}
+
/* This function is equivalent to isalnum() for multibyte characters. */
bool is_alnum_mbchar(const char *c)
{
if (use_utf8) {
wchar_t wc;
- if (mbtowc(&wc, c, MB_CUR_MAX) < 0)
+ if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
wc = bad_wchar;
+ }
return iswalnum(wc);
} else
if (use_utf8) {
wchar_t wc;
- if (mbtowc(&wc, c, MB_CUR_MAX) < 0)
+ if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
wc = bad_wchar;
+ }
return iswblank(wc);
} else
if (use_utf8) {
wchar_t wc;
- if (mbtowc(&wc, c, MB_CUR_MAX) < 0)
+ if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
wc = bad_wchar;
+ }
return is_cntrl_wchar(wc);
} else
if (use_utf8) {
wchar_t wc;
- if (mbtowc(&wc, c, MB_CUR_MAX) < 0)
+ if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
wc = bad_wchar;
+ }
return iswpunct(wc);
} else
wchar_t wc;
if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
*crep_len = bad_mbchar_len;
strncpy(crep, bad_mbchar, *crep_len);
} else {
*crep_len = wctomb(crep, control_wrep(wc));
- if (*crep_len < 0)
+ if (*crep_len < 0) {
+ wctomb_reset();
*crep_len = 0;
+ }
}
} else {
#endif
/* Reject invalid Unicode characters. */
if (mbtowc(&wc, c, MB_CUR_MAX) < 0 || !is_valid_unicode(wc)) {
+ mbtowc_reset();
*crep_len = bad_mbchar_len;
strncpy(crep, bad_mbchar, *crep_len);
} else {
*crep_len = wctomb(crep, wc);
- if (*crep_len < 0)
+ if (*crep_len < 0) {
+ wctomb_reset();
*crep_len = 0;
+ }
}
} else {
#endif
wchar_t wc;
int width;
- if (mbtowc(&wc, c, MB_CUR_MAX) < 0)
+ if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
wc = bad_wchar;
+ }
width = wcwidth(wc);
- if (width == -1)
- width = wcwidth(bad_wchar);
+ if (width == -1) {
+ wc = bad_wchar;
+ width = wcwidth(wc);
+ }
return width;
} else
*chr_mb_len = wctomb(chr_mb, (wchar_t)chr);
/* Reject invalid Unicode characters. */
- if (*chr_mb_len < 0 || !is_valid_unicode((wchar_t)chr))
+ if (*chr_mb_len < 0 || !is_valid_unicode((wchar_t)chr)) {
+ wctomb_reset();
*chr_mb_len = 0;
+ }
} else {
#endif
*chr_mb_len = 1;
s1_mb_len = parse_mbchar(s1, s1_mb, NULL);
if (mbtowc(&ws1, s1_mb, s1_mb_len) < 0) {
+ mbtowc_reset();
ws1 = (unsigned char)*s1_mb;
bad_s1_mb = TRUE;
}
s2_mb_len = parse_mbchar(s2, s2_mb, NULL);
if (mbtowc(&ws2, s2_mb, s2_mb_len) < 0) {
+ mbtowc_reset();
ws2 = (unsigned char)*s2_mb;
bad_s2_mb = TRUE;
}
wchar_t ws, wc;
if (mbtowc(&wc, c, MB_CUR_MAX) < 0) {
+ mbtowc_reset();
wc = (unsigned char)*c;
bad_c_mb = TRUE;
}
int s_mb_len = parse_mbchar(s, s_mb, NULL);
if (mbtowc(&ws, s_mb, s_mb_len) < 0) {
+ mbtowc_reset();
ws = (unsigned char)*s;
bad_s_mb = TRUE;
}