diff options
author | Corinna Vinschen <corinna@vinschen.de> | 2025-07-22 14:54:47 +0200 |
---|---|---|
committer | Corinna Vinschen <corinna@vinschen.de> | 2025-07-24 10:12:48 +0200 |
commit | ba962ee04543855cfc6e2dc79a7369a78218815a (patch) | |
tree | 28bdde9be20eab092da833d4e5abca868e1f7c7f /newlib/libc/stdio/vasniprintf.c | |
parent | 9e0162a18d7db74f8692789bf726aa753540fb51 (diff) | |
download | newlib-ba962ee04543855cfc6e2dc79a7369a78218815a.zip newlib-ba962ee04543855cfc6e2dc79a7369a78218815a.tar.gz newlib-ba962ee04543855cfc6e2dc79a7369a78218815a.tar.bz2 |
Revert "mbrtowc: fix handling invalid UTF-8 4 byte sequences if wchar_t == UTF-16"
This reverts commit b374973d14ac7969b10ba719feedc709f6971c0d.
Turns out this patch breaks mbrtowc. Example:
--- SNIP ---
void mb(unsigned char c)
{
wchar_t wc;
int ret = mbrtowc(&wc, &c, 1, 0);
printf("%02X -> %04X : %d\n", c, wc, ret);
}
void main ()
{
setlocale (LC_CTYPE, "");
mb(0xF0);
mb(0x9F);
mb(0x98);
mb(0x8E);
}
--- SNAP ---
Output before commit b374973d14ac:
F0 -> 0000 : -2
9F -> 0000 : -2
98 -> D83D : 1
8E -> DE0E : 1
Output after commit b374973d14ac:
F0 -> 0000 : -2
9F -> 0000 : -2
98 -> 0000 : -2
8E -> D83D : 3
By using mbrtowc(), the high surrogate is only emitted after byte 4, and
there's no way to recover the low surrogate. The byte count is also incorrect.
Conclusion: We have to emit the high surrogate already after byte 3
to be able to emit the low surrogate after byte 4.
Reported-by: Thomas Wolff <towo@towo.net>
Addresses: https://cygwin.com/pipermail/cygwin/2025-July/258513.html
Fixes: b374973d14ac ("mbrtowc: fix handling invalid UTF-8 4 byte sequences if wchar_t == UTF-16")
Signed-off-by: Corinna Vinschen <corinna@vinschen.de>
Diffstat (limited to 'newlib/libc/stdio/vasniprintf.c')
0 files changed, 0 insertions, 0 deletions