From a8420d6d0fdf98b5a4bb87dfb4e676b3e6cc7d0a Mon Sep 17 00:00:00 2001 From: Karel Balej Date: Tue, 15 Aug 2023 22:21:18 +0200 Subject: [PATCH] musl: backport patch to fix fgetws --- srcpkgs/musl/patches/fgetws.patch | 61 +++++++++++++++++++++++++++++++ srcpkgs/musl/template | 2 +- 2 files changed, 62 insertions(+), 1 deletion(-) create mode 100644 srcpkgs/musl/patches/fgetws.patch diff --git a/srcpkgs/musl/patches/fgetws.patch b/srcpkgs/musl/patches/fgetws.patch new file mode 100644 index 0000000000000..c85c874279eab --- /dev/null +++ b/srcpkgs/musl/patches/fgetws.patch @@ -0,0 +1,61 @@ +From f8bdc3048216f41eaaf655524fa286cfb1184a70 Mon Sep 17 00:00:00 2001 +From: Rich Felker +Date: Sun, 20 Feb 2022 20:11:14 -0500 +Subject: [PATCH] fix spurious failures by fgetws when buffer ends with partial + character + +commit a90d9da1d1b14d81c4f93e1a6d1a686c3312e4ba made fgetws look for +changes to errno by fgetwc to detect encoding errors, since ISO C did +not allow the implementation to set the stream's error flag in this +case, and the fgetwc interface did not admit any other way to detect +the error. however, the possibility of fgetwc setting errno to EILSEQ +in the success path was overlooked, and in fact this can happen if the +buffer ends with a partial character, causing mbtowc to be called with +only part of the character available. + +since that change was made, the C standard was amended to specify that +fgetwc set the stream error flag on encoding errors, and commit +511d70738bce11a67219d0132ce725c323d00e4e made it do so. thus, there is +no longer any need for fgetws to poke at errno to handle encoding +errors. + +this commit reverts commit a90d9da1d1b14d81c4f93e1a6d1a686c3312e4ba +and thereby fixes the problem. +--- + src/stdio/fgetws.c | 7 +------ + 1 file changed, 1 insertion(+), 6 deletions(-) + +diff --git a/src/stdio/fgetws.c b/src/stdio/fgetws.c +index b08b3049..195cb435 100644 +--- a/src/stdio/fgetws.c ++++ b/src/stdio/fgetws.c +@@ -1,6 +1,5 @@ + #include "stdio_impl.h" + #include +-#include + + wint_t __fgetwc_unlocked(FILE *); + +@@ -12,10 +11,6 @@ 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; + for (; n; n--) { + wint_t c = __fgetwc_unlocked(f); + if (c == WEOF) break; +@@ -23,7 +18,7 @@ wchar_t *fgetws(wchar_t *restrict s, int n, FILE *restrict f) + if (c == '\n') break; + } + *p = 0; +- if (ferror(f) || errno==EILSEQ) p = s; ++ if (ferror(f)) p = s; + + FUNLOCK(f); + +-- +2.41.0 + diff --git a/srcpkgs/musl/template b/srcpkgs/musl/template index 6c98fac0962e9..9838f9ad9e613 100644 --- a/srcpkgs/musl/template +++ b/srcpkgs/musl/template @@ -2,7 +2,7 @@ pkgname=musl reverts="1.2.0_1" version=1.1.24 -revision=18 +revision=19 archs="*-musl" bootstrap=yes build_style=gnu-configure