From: Pinghao Wu <xdavidwuph@gmail.com>
To: musl@lists.openwall.com
Cc: Pinghao Wu <xdavidwuph@gmail.com>
Subject: [musl] [PATCH] fgetws: fix checking for fgetwc errors
Date: Thu, 10 Feb 2022 02:47:36 +0800 [thread overview]
Message-ID: <20220209184736.26792-1-xdavidwuph@gmail.com> (raw)
This corrects checking for fgetwc errors by arming dummy errno before
each invocation, and checking errors only if it returns WEOF.
---
src/stdio/fgetws.c | 13 +++++++------
1 file changed, 7 insertions(+), 6 deletions(-)
diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c
index b08b3049..edcd769b 100644
--- a/src/stdio/fgetws.c
+++ b/src/stdio/fgetws.c
@@ -12,18 +12,19 @@ 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;
+ wint_t c;
for (; n; n--) {
- wint_t c = __fgetwc_unlocked(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;
+ c = __fgetwc_unlocked(f);
if (c == WEOF) break;
*p++ = c;
if (c == '\n') break;
}
*p = 0;
- if (ferror(f) || errno==EILSEQ) p = s;
+ if (c == WEOF && (ferror(f) || errno==EILSEQ)) p = s;
FUNLOCK(f);
--
2.35.1
next reply other threads:[~2022-02-09 18:49 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-09 18:47 Pinghao Wu [this message]
2022-02-09 20:11 ` Rich Felker
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20220209184736.26792-1-xdavidwuph@gmail.com \
--to=xdavidwuph@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).