Hi, i just noticed a bug in fgetwc(3) in our libc, the function used to implement getwc(3), getwchar(3), getws(3), getwln(3) and the wscanf(3) family of functions. In case of an encoding error, it does not set the error indicator, such that a program correctly checking ferror(3) after WEOF may miss the error.
Our manual says: If the stream is at end-of-file or a read error occurs, the routines return WEOF. The routines feof(3) and ferror(3) must be used to distinguish between end-of-file and error. POSIX is even more explicit: If an encoding error occurs, the error indicator for the stream shall be set, fgetwc() shall return WEOF, and shall set errno to indicate the error. Besides, setting errno is pointless; mbrtowc(3) already did that, and the standard requires it to do so. OK? Ingo Index: stdio/fgetwc.c =================================================================== RCS file: /cvs/src/lib/libc/stdio/fgetwc.c,v retrieving revision 1.5 diff -u -p -r1.5 fgetwc.c --- stdio/fgetwc.c 31 Aug 2015 02:53:57 -0000 1.5 +++ stdio/fgetwc.c 23 Dec 2015 17:05:42 -0000 @@ -69,7 +69,7 @@ __fgetwc_unlock(FILE *fp) c = ch; size = mbrtowc(&wc, &c, 1, st); if (size == (size_t)-1) { - errno = EILSEQ; + fp->_flags |= __SERR; return WEOF; } } while (size == (size_t)-2);