Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 1 Sep 2016 20:45:05 +0000 (UTC)
From:      "Andrey A. Chernov" <ache@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r305241 - head/lib/libc/stdio
Message-ID:  <201609012045.u81Kj5hc052011@repo.freebsd.org>

next in thread | raw e-mail | index | archive | help
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);



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201609012045.u81Kj5hc052011>