svn commit: r305404 - stable/11/lib/libc/stdio

Andrey A. Chernov ache at FreeBSD.org
Mon Sep 5 02:00:36 UTC 2016


Author: ache
Date: Mon Sep  5 02:00:35 2016
New Revision: 305404
URL: https://svnweb.freebsd.org/changeset/base/305404

Log:
  MFC r305241
  
  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.

Modified:
  stable/11/lib/libc/stdio/fgetwln.c
Directory Properties:
  stable/11/   (props changed)

Modified: stable/11/lib/libc/stdio/fgetwln.c
==============================================================================
--- stable/11/lib/libc/stdio/fgetwln.c	Mon Sep  5 01:57:32 2016	(r305403)
+++ stable/11/lib/libc/stdio/fgetwln.c	Mon Sep  5 02:00:35 2016	(r305404)
@@ -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