mailing list of musl libc
 help / color / mirror / code / Atom feed
* [musl] [PATCH] fgetwc: fix errno when character span aver buffer end
@ 2022-02-09 17:55 Pinghao Wu
  2022-02-09 18:24 ` Rich Felker
  0 siblings, 1 reply; 2+ messages in thread
From: Pinghao Wu @ 2022-02-09 17:55 UTC (permalink / raw)
  To: musl; +Cc: Pinghao Wu

If attempt on converting character from buffer failed, errno is set to
EILSEQ by mbtowc. As a result, if further byte-by-byte conversion
succeeds, fgetwc will return a valid wchar with a misleading EILSEQ as
errno. This fixes it by saving errno before the from buffer attempt, and
restore if it fails.

This also fixes fgetws which find the misleading EILSEQ and fails in
this case.
---
 src/stdio/fgetwc.c | 2 ++
 1 file changed, 2 insertions(+)

diff --git a/src/stdio/fgetwc.c b/src/stdio/fgetwc.c
index aa10b818..9dad0505 100644
--- a/src/stdio/fgetwc.c
+++ b/src/stdio/fgetwc.c
@@ -8,6 +8,7 @@ static wint_t __fgetwc_unlocked_internal(FILE *f)
 	wchar_t wc;
 	int c;
 	size_t l;
+	int errno_save = errno;
 
 	/* Convert character from buffer if possible */
 	if (f->rpos != f->rend) {
@@ -16,6 +17,7 @@ static wint_t __fgetwc_unlocked_internal(FILE *f)
 			f->rpos += l + !l; /* l==0 means 1 byte, null */
 			return wc;
 		}
+		errno = errno_save;
 	}
 
 	/* Convert character byte-by-byte */
-- 
2.35.1


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-02-09 18:25 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-09 17:55 [musl] [PATCH] fgetwc: fix errno when character span aver buffer end Pinghao Wu
2022-02-09 18:24 ` Rich Felker

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).