diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-08-27 12:08:39 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2016-08-27 12:08:39 +0000 |
commit | ae88fc4da01e4fd80a33f8bffd3e43ed2e6960be (patch) | |
tree | e86249f64cec51afb75164b441edf365cb61ecc7 /lib/libc | |
parent | d73ca0f05de11870795e8c36e9e4e35bd6d5c655 (diff) |
improve revision 1.2: in unusual cases, fgetwc(3) can succeed
even though ferror(3) is already set;
also from Andrey Chernov <ache at freebsd dot org>;
OK millert@
Diffstat (limited to 'lib/libc')
-rw-r--r-- | lib/libc/stdio/fgetwln.c | 14 |
1 files changed, 12 insertions, 2 deletions
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); |