From: schwarze Date: Sat, 27 Aug 2016 12:08:38 +0000 (+0000) Subject: improve revision 1.2: in unusual cases, fgetwc(3) can succeed X-Git-Url: http://artulab.com/gitweb/?a=commitdiff_plain;h=1c50512a2b2262363e327edc19370b2d0339ca11;p=openbsd improve revision 1.2: in unusual cases, fgetwc(3) can succeed even though ferror(3) is already set; also from Andrey Chernov ; OK millert@ --- diff --git a/lib/libc/stdio/fgetwln.c b/lib/libc/stdio/fgetwln.c index 2ee7e8d61e6..aba11b5b285 100644 --- a/lib/libc/stdio/fgetwln.c +++ b/lib/libc/stdio/fgetwln.c @@ -1,4 +1,4 @@ -/* $OpenBSD: fgetwln.c,v 1.3 2016/08/24 18:35:12 schwarze Exp $ */ +/* $OpenBSD: fgetwln.c,v 1.4 2016/08/27 12:08:38 schwarze Exp $ */ /*- * Copyright (c) 2002-2004 Tim J. Robbins. @@ -69,7 +69,17 @@ fgetwln(FILE * __restrict fp, size_t *lenp) if (wc == L'\n') break; } - if (len == 0 || fp->_flags & __SERR) + + /* + * The following test assumes that fgetwc() fails when + * feof() is already set, and that fgetwc() will never + * set feof() in the same call where it also sets ferror() + * or returns non-WEOF. + * Testing ferror() would not be better because fgetwc() + * may succeed even when ferror() is already set. + */ + + if (len == 0 || (wc == WEOF && !__sfeof(fp))) goto error; FUNLOCKFILE(fp);