svn commit: r305241 - head/lib/libc/stdio

Andrey A. Chernov ache at FreeBSD.org
Thu Sep 1 20:45:06 UTC 2016


Author: ache
Date: Thu Sep  1 20:45:04 2016
New Revision: 305241
URL: https://svnweb.freebsd.org/changeset/base/305241

Log:
  fgetwc(3) may set both __SEOF and __SERR at once (in case of incomplete
  sequence near EOF), so we can't just check for
  (wc == WEOF && !__sfeof(fp)) and must relay on __sferror(fp) with
  __SERR clearing/restoring.
  
  MFC after:      7 days

Modified:
  head/lib/libc/stdio/fgetwln.c

Modified: head/lib/libc/stdio/fgetwln.c
==============================================================================
--- head/lib/libc/stdio/fgetwln.c	Thu Sep  1 20:43:01 2016	(r305240)
+++ head/lib/libc/stdio/fgetwln.c	Thu Sep  1 20:45:04 2016	(r305241)
@@ -47,11 +47,16 @@ fgetwln_l(FILE * __restrict fp, size_t *
 {
 	wint_t wc;
 	size_t len;
+	int savserr;
+
 	FIX_LOCALE(locale);
 
 	FLOCKFILE(fp);
 	ORIENT(fp, 1);
 
+	savserr = fp->_flags & __SERR;
+	fp->_flags &= ~__SERR;
+
 	len = 0;
 	while ((wc = __fgetwc(fp, locale)) != WEOF) {
 #define	GROW	512
@@ -64,7 +69,12 @@ fgetwln_l(FILE * __restrict fp, size_t *
 		if (wc == L'\n')
 			break;
 	}
-	if (len == 0 || (wc == WEOF && !__sfeof(fp)))
+	/* fgetwc(3) may set both __SEOF and __SERR at once. */
+	if (__sferror(fp))
+		goto error;
+
+	fp->_flags |= savserr;
+	if (len == 0)
 		goto error;
 
 	FUNLOCKFILE(fp);


More information about the svn-src-all mailing list