[uClibc-cvs] uClibc/libc/stdio scanf.c,1.28,1.29
Manuel Novoa III
mjn3 at uclibc.org
Mon Aug 18 21:15:58 UTC 2003
Update of /var/cvs/uClibc/libc/stdio
In directory winder:/tmp/cvs-serv15198
Modified Files:
scanf.c
Log Message:
scanf %lc,%ls,%l[ would always set mb_fail on eof or error,
even when just starting a new mb char.
wscanf would incorrectly unget in certain situations.
Index: scanf.c
===================================================================
RCS file: /var/cvs/uClibc/libc/stdio/scanf.c,v
retrieving revision 1.28
retrieving revision 1.29
diff -u -d -r1.28 -r1.29
--- scanf.c 1 Aug 2003 20:08:53 -0000 1.28
+++ scanf.c 18 Aug 2003 21:15:55 -0000 1.29
@@ -20,6 +20,11 @@
* Also now optionally supports hexadecimal float notation, positional
* args, and glibc locale-specific digit grouping. Should now be
* standards compliant.
+ *
+ * Aug 18, 2003
+ * Bug fix: scanf %lc,%ls,%l[ would always set mb_fail on eof or error,
+ * even when just starting a new mb char.
+ * Bug fix: wscanf would incorrectly unget in certain situations.
*/
@@ -829,7 +834,9 @@
width = sc->width; /* Preserve width. */
sc->width = INT_MAX; /* MB_CUR_MAX can invoke a function. */
- r = (size_t)(-1);
+ assert(!sc->mb_fail);
+
+ r = (size_t)(-3);
while (__scan_getc(sc) >= 0) {
*b = sc->cc;
@@ -844,12 +851,17 @@
break;
}
- /* If we reach here, either r == ((size_t)-1) and
- * mbrtowc set errno to EILSEQ, or r == ((size_t)-2)
- * and stream is in an error state or at EOF with a
- * partially complete wchar. */
- __set_errno(EILSEQ); /* In case of incomplete conversion. */
- sc->mb_fail = 1;
+ if (r == ((size_t)(-3))) { /* EOF or ERROR on first read */
+ sc->wc = WEOF;
+ r = (size_t)(-1);
+ } else {
+ /* If we reach here, either r == ((size_t)-1) and
+ * mbrtowc set errno to EILSEQ, or r == ((size_t)-2)
+ * and stream is in an error state or at EOF with a
+ * partially complete wchar. */
+ __set_errno(EILSEQ); /* In case of incomplete conversion. */
+ sc->mb_fail = 1;
+ }
SUCCESS:
sc->width = width; /* Restore width. */
@@ -961,7 +973,9 @@
#else
- if ((sc->ungot_wflag & 1) && (sc->fp->filedes != -3) && (sc->fp->state.mask == 0)) {
+ if ((sc->ungot_flag & 1) && (sc->ungot_wflag & 1)
+ && (sc->fp->filedes != -3) && (sc->fp->state.mask == 0)
+ ) {
ungetwc(sc->ungot_char, sc->fp);
/* Deal with distiction between user and scanf ungots. */
if (sc->nread == 0) { /* Only one char was read... app ungot? */
More information about the uClibc-cvs
mailing list