mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 08:55:19 +00:00
[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 destination wide string parameter thus never calling MultiByteToWideChar(). Installing WINE Gecko merely unhides this problem. 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
This commit is contained in:
parent
8ce31ad749
commit
8266f62ff6
1 changed files with 19 additions and 11 deletions
|
@ -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;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue