mlibc: backport mbtowc fix

This commit is contained in:
Matheus
2026-05-30 12:46:01 -03:00
parent 8a94de445f
commit 5cbad2b060
+24
View File
@@ -11,6 +11,30 @@ index 71033d0..4d40869 100644
}
}
while (true) {
diff --git mlibc-clean/options/ansi/generic/stdlib.cpp mlibc-workdir/options/ansi/generic/stdlib.cpp
index ac05b7a..967d759 100644
--- mlibc-clean/options/ansi/generic/stdlib.cpp
+++ mlibc-workdir/options/ansi/generic/stdlib.cpp
@@ -447,7 +447,6 @@ int mblen(const char *mbs, size_t mb_limit) {
int mbtowc(wchar_t *__restrict wc, const char *__restrict mb, size_t max_size) {
auto cc = mlibc::current_charcode();
- __ensure(max_size);
// If wc is NULL, decode into a single local character which we discard
// to obtain the length.
@@ -457,6 +456,11 @@ int mbtowc(wchar_t *__restrict wc, const char *__restrict mb, size_t max_size) {
if (mb) {
if (*mb) {
+ if (max_size == 0) {
+ errno = EILSEQ;
+ return -1;
+ }
+
mlibc::code_seq<wchar_t> wseq{wc, wc + 1};
mlibc::code_seq<const char> nseq{mb, mb + frg::min(max_size, MB_CUR_MAX)};
auto e = cc->decode_wtranscode(nseq, wseq, mbtowc_state);
diff --git mlibc-clean/options/glibc/generic/execinfo.cpp mlibc-workdir/options/glibc/generic/execinfo.cpp
index 1ed110d..ded9114 100644
--- mlibc-clean/options/glibc/generic/execinfo.cpp