From: Piotr Caban piotr@codeweavers.com
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=56994 --- dlls/msvcrt/mbcs.c | 16 +++++++++++++++- dlls/ucrtbase/tests/string.c | 23 +++++++++++++++++++++++ 2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/dlls/msvcrt/mbcs.c b/dlls/msvcrt/mbcs.c index 0bac4c9f8d9..5f5cd3e8cda 100644 --- a/dlls/msvcrt/mbcs.c +++ b/dlls/msvcrt/mbcs.c @@ -3266,6 +3266,17 @@ size_t CDECL mbrtowc(wchar_t *dst, const char *str, return len; }
+static inline int get_utf8_char_len(char ch) +{ + if((ch&0xf8) == 0xf0) + return 4; + else if((ch&0xf0) == 0xe0) + return 3; + else if((ch&0xe0) == 0xc0) + return 2; + return 1; +} + /********************************************************************* * _mbstowcs_l(MSVCRT.@) */ @@ -3311,7 +3322,10 @@ size_t CDECL _mbstowcs_l(wchar_t *wcstr, const char *mbstr, if(mbstr[size] == '\0') break;
- size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1); + if (locinfo->lc_codepage == CP_UTF8) + size += get_utf8_char_len(mbstr[size]); + else + size += (_isleadbyte_l((unsigned char)mbstr[size], locale) ? 2 : 1); }
if(size) { diff --git a/dlls/ucrtbase/tests/string.c b/dlls/ucrtbase/tests/string.c index 5714d384b05..d6085650e98 100644 --- a/dlls/ucrtbase/tests/string.c +++ b/dlls/ucrtbase/tests/string.c @@ -815,6 +815,28 @@ static void test__mbsncpy_s(void) _setmbcp(oldcp); }
+static void test_mbstowcs(void) +{ + static const char mbs[] = { 0xc3, 0xa9 }; + WCHAR wcs[2]; + size_t ret; + + if (!setlocale(LC_ALL, "en_US.UTF-8")) + { + win_skip("skipping UTF8 mbstowcs tests\n"); + return; + } + + ret = mbstowcs(NULL, mbs, 0); + ok(ret == 1, "mbstowcs returned %Id\n", ret); + memset(wcs, 0xfe, sizeof(wcs)); + ret = mbstowcs(wcs, mbs, 1); + ok(ret == 1, "mbstowcs returned %Id\n", ret); + ok(wcs[0] == 0xe9, "wcsstring[0] = %x\n", wcs[0]); + ok(wcs[1] == 0xfefe, "wcsstring[1] = %x\n", wcs[1]); + setlocale(LC_ALL, "C"); +} + START_TEST(string) { ok(_set_invalid_parameter_handler(test_invalid_parameter_handler) == NULL, @@ -834,4 +856,5 @@ START_TEST(string) test__mbbtype_l(); test_strcmp(); test__mbsncpy_s(); + test_mbstowcs(); }
Hi,
It looks like your patch introduced the new failures shown below. Please investigate and fix them before resubmitting your patch. If they are not new, fixing them anyway would help a lot. Otherwise please ask for the known failures list to be updated.
The tests also ran into some preexisting test failures. If you know how to fix them that would be helpful. See the TestBot job for the details:
The full results can be found at: https://testbot.winehq.org/JobDetails.pl?Key=147275
Your paranoid android.
=== w1064v1809 (32 bit report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== w1064_tsign (32 bit report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== w10pro64 (32 bit report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== w10pro64_en_AE_u8 (32 bit report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== w11pro64 (32 bit report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit ar:MA report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit de report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit fr report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit he:IL report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit hi:IN report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit ja:JP report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11 (32 bit zh:CN report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18
=== debian11b (32 bit WoW report) ===
ucrtbase: string.c:831: Test failed: mbstowcs returned 18