|
|
Message-Id: <20220210030813.1943-1-xdavidwuph@gmail.com>
Date: Thu, 10 Feb 2022 11:08:13 +0800
From: Pinghao Wu <xdavidwuph@...il.com>
To: musl@...ts.openwall.com
Cc: Pinghao Wu <xdavidwuph@...il.com>
Subject: [PATCH v2] fgetws: fix checking for fgetwc errors
This corrects checking for fgetwc errors by arming dummy errno before
each invocation, and checking errors only if it returns WEOF.
---
v2: move error checking into the loop.
src/stdio/fgetws.c | 16 ++++++++++------
1 file changed, 10 insertions(+), 6 deletions(-)
diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c
index b08b3049..cffff84a 100644
--- a/src/stdio/fgetws.c
+++ b/src/stdio/fgetws.c
@@ -12,18 +12,22 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f)
FLOCK(f);
- /* Setup a dummy errno so we can detect EILSEQ. This is
- * the only way to catch encoding errors in the form of a
- * partial character just before EOF. */
- errno = EAGAIN;
+ int err = 0;
for (; n; n--) {
+ /* Setup a dummy errno so we can detect EILSEQ. This is
+ * the only way to catch encoding errors in the form of a
+ * partial character just before EOF. */
+ errno = EAGAIN;
wint_t c = __fgetwc_unlocked(f);
- if (c == WEOF) break;
+ if (c == WEOF) {
+ if (ferror(f) || errno == EILSEQ) err = 1;
+ break;
+ }
*p++ = c;
if (c == '\n') break;
}
*p = 0;
- if (ferror(f) || errno==EILSEQ) p = s;
+ if (err) p = s;
FUNLOCK(f);
--
2.35.1
Powered by blists - more mailing lists
Confused about mailing lists and their use? Read about mailing lists on Wikipedia and check out these guidelines on proper formatting of your messages.