diff options
author | tjr <tjr@FreeBSD.org> | 2002-10-16 12:09:43 +0000 |
---|---|---|
committer | tjr <tjr@FreeBSD.org> | 2002-10-16 12:09:43 +0000 |
commit | 3a88c84c050889dfcdf58a721602c40f9ae03a96 (patch) | |
tree | 47fcbdba053baaebb80400ad1d663fa57af766bc /lib | |
parent | ccd9275d4ea58567606a870a1c0faabbbabd889b (diff) | |
download | FreeBSD-src-3a88c84c050889dfcdf58a721602c40f9ae03a96.zip FreeBSD-src-3a88c84c050889dfcdf58a721602c40f9ae03a96.tar.gz |
Set the error bit on the stream if an encoding error occurs. Improve
handling of multibyte sequences representing null wide characters.
Diffstat (limited to 'lib')
-rw-r--r-- | lib/libc/stdio/fgetwc.c | 1 | ||||
-rw-r--r-- | lib/libc/stdio/fputwc.c | 4 | ||||
-rw-r--r-- | lib/libc/stdio/ungetwc.c | 4 | ||||
-rw-r--r-- | lib/libc/stdio/vfprintf.c | 8 | ||||
-rw-r--r-- | lib/libc/stdio/vfscanf.c | 46 | ||||
-rw-r--r-- | lib/libc/stdio/vfwprintf.c | 4 |
6 files changed, 52 insertions, 15 deletions
diff --git a/lib/libc/stdio/fgetwc.c b/lib/libc/stdio/fgetwc.c index 311391a..93438a6 100644 --- a/lib/libc/stdio/fgetwc.c +++ b/lib/libc/stdio/fgetwc.c @@ -104,5 +104,6 @@ __fgetwc_nbf(FILE *fp) while (n-- != 0) __ungetc((unsigned char)buf[n], fp); errno = EILSEQ; + fp->_flags |= __SERR; return (WEOF); } diff --git a/lib/libc/stdio/fputwc.c b/lib/libc/stdio/fputwc.c index 10c3c18..1f42ce9 100644 --- a/lib/libc/stdio/fputwc.c +++ b/lib/libc/stdio/fputwc.c @@ -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++) diff --git a/lib/libc/stdio/ungetwc.c b/lib/libc/stdio/ungetwc.c index 5eeb8b1..e20a763 100644 --- a/lib/libc/stdio/ungetwc.c +++ b/lib/libc/stdio/ungetwc.c @@ -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); diff --git a/lib/libc/stdio/vfprintf.c b/lib/libc/stdio/vfprintf.c index c1b4e0b..b0084c8 100644 --- a/lib/libc/stdio/vfprintf.c +++ b/lib/libc/stdio/vfprintf.c @@ -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) diff --git a/lib/libc/stdio/vfscanf.c b/lib/libc/stdio/vfscanf.c index f6480f1..d825034 100644 --- a/lib/libc/stdio/vfscanf.c +++ b/lib/libc/stdio/vfscanf.c @@ -383,15 +383,21 @@ literal: 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 @@ literal: 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 @@ literal: 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 @@ literal: 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 @@ literal: 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 @@ literal: n = 0; } if (fp->_r <= 0 && __srefill(fp)) { - if (n != 0) + if (n != 0) { + fp->_flags |= __SERR; goto input_failure; + } break; } } diff --git a/lib/libc/stdio/vfwprintf.c b/lib/libc/stdio/vfwprintf.c index e452744..1415dd3 100644 --- a/lib/libc/stdio/vfwprintf.c +++ b/lib/libc/stdio/vfwprintf.c @@ -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; } } |