summaryrefslogtreecommitdiffstats
path: root/lib/libc/stdio/vfscanf.c
diff options
context:
space:
mode:
authortjr <tjr@FreeBSD.org>2002-10-16 12:09:43 +0000
committertjr <tjr@FreeBSD.org>2002-10-16 12:09:43 +0000
commit3a88c84c050889dfcdf58a721602c40f9ae03a96 (patch)
tree47fcbdba053baaebb80400ad1d663fa57af766bc /lib/libc/stdio/vfscanf.c
parentccd9275d4ea58567606a870a1c0faabbbabd889b (diff)
downloadFreeBSD-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/libc/stdio/vfscanf.c')
-rw-r--r--lib/libc/stdio/vfscanf.c46
1 files changed, 36 insertions, 10 deletions
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;
}
}
OpenPOWER on IntegriCloud