https://git.reactos.org/?p=reactos.git;a=commitdiff;h=8266f62ff6881cc321061…
commit 8266f62ff6881cc3210617b5eca7bbd2b2644f35
Author: Bișoc George <fraizeraust99(a)gmail.com>
AuthorDate: Tue Apr 21 11:28:07 2020 +0200
Commit: Mark Jansen <mark.jansen(a)reactos.org>
CommitDate: Tue Apr 28 22:41:57 2020 +0200
[CRT][STDLIB] Wine-sync _mbtowc_l function code
The current _mbtowc_l code directly passes the string count size argument to
cbMultiByte argument parameter to MultiByteToWideChar(). As the size of lpMultiByteStr
expressed in bytes by cbMultiByte is dependent of the actual given string, the size of
lpWideCharStr expressed in characters by cchWideChar is always 1.
The resulting parameters to MultiByteToWideChar() will lead to a failure as
lpWideCharStr cannot accommodate the converted string if the size pointed by
lpMultiByteStr is larger than the buffer wide string to receive the converted output, a
Win32 error code of ERROR_INSUFFICIENT_BUFFER in other words. The fact that _mbtowc_l
never fails without WINE Gecko package installed is because the codepage pointed by
lc_codepage is CP_ACP and the converted output is directly given to the destin [...]
As _mbtowc_l is imported from WINE and that they have updated their code (which at the
same time this fixes the aforementioned problem), the following commit syncs the updated
code from WINE.
CORE-16885
---
sdk/lib/crt/stdlib/mbtowc.c | 30 +++++++++++++++++++-----------
1 file changed, 19 insertions(+), 11 deletions(-)
diff --git a/sdk/lib/crt/stdlib/mbtowc.c b/sdk/lib/crt/stdlib/mbtowc.c
index 5ccb7e3a2e8..41bd0234f74 100644
--- a/sdk/lib/crt/stdlib/mbtowc.c
+++ b/sdk/lib/crt/stdlib/mbtowc.c
@@ -18,24 +18,32 @@ int CDECL _mbtowc_l(wchar_t *dst, const char* str, size_t n, _locale_t
locale)
MSVCRT_pthreadlocinfo locinfo;
wchar_t tmpdst = '\0';
- if(!locale)
+ if (!locale)
locinfo = get_locinfo();
else
locinfo = (MSVCRT_pthreadlocinfo)(locale->locinfo);
- if(n <= 0 || !str)
+ if (n <= 0 || !str)
return 0;
- if(!locinfo->lc_codepage)
- tmpdst = (unsigned char)*str;
- else if(!MultiByteToWideChar(locinfo->lc_codepage, 0, str, n, &tmpdst, 1))
- return -1;
- if(dst)
- *dst = tmpdst;
- /* return the number of bytes from src that have been used */
- if(!*str)
+
+ if (!*str) {
+ if (dst) *dst = 0;
return 0;
- if(n >= 2 && _isleadbyte_l((unsigned char)*str, locale) &&
str[1])
+ }
+
+ if (!locinfo->lc_codepage) {
+ if (dst) *dst = (unsigned char)*str;
+ return 1;
+ }
+ if (n >= 2 && _isleadbyte_l((unsigned char)*str, locale)) {
+ if (!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 2, &tmpdst, 1))
+ return -1;
+ if (dst) *dst = tmpdst;
return 2;
+ }
+ if (!MultiByteToWideChar(locinfo->lc_codepage, 0, str, 1, &tmpdst, 1))
+ return -1;
+ if (dst) *dst = tmpdst;
return 1;
}