Date: Mon, 5 Sep 2016 01:57:32 +0000 (UTC) From: "Andrey A. Chernov" <ache@FreeBSD.org> To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-10@freebsd.org Subject: svn commit: r305403 - stable/10/lib/libc/stdio Message-ID: <201609050157.u851vWjX038539@repo.freebsd.org>
next in thread | raw e-mail | index | archive | help
Author: ache Date: Mon Sep 5 01:57:32 2016 New Revision: 305403 URL: https://svnweb.freebsd.org/changeset/base/305403 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/10/lib/libc/stdio/fgetwln.c Directory Properties: stable/10/ (props changed) Modified: stable/10/lib/libc/stdio/fgetwln.c ============================================================================== --- stable/10/lib/libc/stdio/fgetwln.c Mon Sep 5 00:41:17 2016 (r305402) +++ stable/10/lib/libc/stdio/fgetwln.c Mon Sep 5 01:57:32 2016 (r305403) @@ -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?201609050157.u851vWjX038539>