Set the error bit on the stream if an encoding error occurs. Improve
handling of multibyte sequences representing null wide characters.
This commit is contained in:
parent
9acd2d9b3c
commit
6180233fd8
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=105234
@ -104,5 +104,6 @@ __fgetwc_nbf(FILE *fp)
|
||||
while (n-- != 0)
|
||||
__ungetc((unsigned char)buf[n], fp);
|
||||
errno = EILSEQ;
|
||||
fp->_flags |= __SERR;
|
||||
return (WEOF);
|
||||
}
|
||||
|
@ -57,8 +57,10 @@ __fputwc(wchar_t wc, FILE *fp)
|
||||
len = 1;
|
||||
} else {
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1)
|
||||
if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
return (WEOF);
|
||||
}
|
||||
}
|
||||
|
||||
for (i = 0; i < len; i++)
|
||||
|
@ -49,8 +49,10 @@ __ungetwc(wint_t wc, FILE *fp)
|
||||
if (wc == WEOF)
|
||||
return (WEOF);
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1)
|
||||
if ((len = wcrtomb(buf, wc, &mbs)) == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
return (WEOF);
|
||||
}
|
||||
while (len-- != 0)
|
||||
if (__ungetc((unsigned char)buf[len], fp) == EOF)
|
||||
return (WEOF);
|
||||
|
@ -759,8 +759,10 @@ reswitch: switch (ch) {
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
mbseqlen = wcrtomb(cp = buf,
|
||||
(wchar_t)GETARG(wint_t), &mbs);
|
||||
if (mbseqlen == (size_t)-1)
|
||||
if (mbseqlen == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto error;
|
||||
}
|
||||
size = (int)mbseqlen;
|
||||
} else {
|
||||
*(cp = buf) = GETARG(int);
|
||||
@ -934,8 +936,10 @@ fp_begin: if (prec == -1)
|
||||
cp = "(null)";
|
||||
else {
|
||||
convbuf = __wcsconv(wcp, prec);
|
||||
if (convbuf == NULL)
|
||||
if (convbuf == NULL) {
|
||||
fp->_flags |= __SERR;
|
||||
goto error;
|
||||
}
|
||||
cp = convbuf;
|
||||
}
|
||||
} else if ((cp = GETARG(char *)) == NULL)
|
||||
|
@ -383,15 +383,21 @@ again: c = *fmt++;
|
||||
wcp = va_arg(ap, wchar_t *);
|
||||
n = 0;
|
||||
while (width != 0) {
|
||||
if (n == MB_CUR_MAX)
|
||||
if (n == MB_CUR_MAX) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
buf[n++] = *fp->_p;
|
||||
fp->_p++;
|
||||
fp->_r--;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
nconv = mbrtowc(wcp, buf, n, &mbs);
|
||||
if (nconv == 0 || nconv == (size_t)-1)
|
||||
if (nconv == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
if (nconv == 0)
|
||||
*wcp = L'\0';
|
||||
if (nconv != (size_t)-2) {
|
||||
nread += n;
|
||||
width--;
|
||||
@ -399,8 +405,10 @@ again: c = *fmt++;
|
||||
n = 0;
|
||||
}
|
||||
if (fp->_r <= 0 && __srefill(fp)) {
|
||||
if (n != 0)
|
||||
if (n != 0) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -440,15 +448,21 @@ again: c = *fmt++;
|
||||
wcp = wcp0 = va_arg(ap, wchar_t *);
|
||||
n = 0;
|
||||
while (width != 0) {
|
||||
if (n == MB_CUR_MAX)
|
||||
if (n == MB_CUR_MAX) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
buf[n++] = *fp->_p;
|
||||
fp->_p++;
|
||||
fp->_r--;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
nconv = mbrtowc(wcp, buf, n, &mbs);
|
||||
if (nconv == 0 || nconv == (size_t)-1)
|
||||
if (nconv == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
if (nconv == 0)
|
||||
*wcp = L'\0';
|
||||
if (nconv != (size_t)-2) {
|
||||
if (wctob(*wcp) != EOF &&
|
||||
!ccltab[wctob(*wcp)]) {
|
||||
@ -463,13 +477,17 @@ again: c = *fmt++;
|
||||
n = 0;
|
||||
}
|
||||
if (fp->_r <= 0 && __srefill(fp)) {
|
||||
if (n != 0)
|
||||
if (n != 0) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (n != 0)
|
||||
if (n != 0) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
n = wcp - wcp0;
|
||||
if (n == 0)
|
||||
goto match_failure;
|
||||
@ -516,15 +534,21 @@ again: c = *fmt++;
|
||||
wcp = va_arg(ap, wchar_t *);
|
||||
n = 0;
|
||||
while (!isspace(*fp->_p) && width != 0) {
|
||||
if (n == MB_CUR_MAX)
|
||||
if (n == MB_CUR_MAX) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
buf[n++] = *fp->_p;
|
||||
fp->_p++;
|
||||
fp->_r--;
|
||||
memset(&mbs, 0, sizeof(mbs));
|
||||
nconv = mbrtowc(wcp, buf, n, &mbs);
|
||||
if (nconv == 0 || nconv == (size_t)-1)
|
||||
if (nconv == (size_t)-1) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
if (nconv == 0)
|
||||
*wcp = L'\0';
|
||||
if (nconv != (size_t)-2) {
|
||||
if (iswspace(*wcp)) {
|
||||
while (--n > 0)
|
||||
@ -538,8 +562,10 @@ again: c = *fmt++;
|
||||
n = 0;
|
||||
}
|
||||
if (fp->_r <= 0 && __srefill(fp)) {
|
||||
if (n != 0)
|
||||
if (n != 0) {
|
||||
fp->_flags |= __SERR;
|
||||
goto input_failure;
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -903,8 +903,10 @@ fp_begin: if (prec == -1)
|
||||
cp = L"(null)";
|
||||
else {
|
||||
convbuf = __mbsconv(mbp, prec);
|
||||
if (convbuf == NULL)
|
||||
if (convbuf == NULL) {
|
||||
fp->_flags |= __SERR;
|
||||
goto error;
|
||||
}
|
||||
cp = convbuf;
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user