msvcrt: Fix _mbstowcs_s_l return value on truncate.

Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Piotr Caban 2019-11-19 23:06:29 +01:00 committed by Alexandre Julliard
parent a9c4b309f6
commit 47217f5979
2 changed files with 10 additions and 3 deletions

View File

@ -2425,6 +2425,7 @@ int CDECL MSVCRT__mbstowcs_s_l(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr,
MSVCRT_size_t count, MSVCRT__locale_t locale)
{
MSVCRT_size_t conv;
int err = 0;
if(!wcstr && !size) {
conv = MSVCRT__mbstowcs_l(NULL, mbstr, 0, locale);
@ -2447,9 +2448,10 @@ int CDECL MSVCRT__mbstowcs_s_l(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr,
conv = MSVCRT__mbstowcs_l(wcstr, mbstr, conv, locale);
if(conv<size)
wcstr[conv++] = '\0';
else if(conv==size && (count==MSVCRT__TRUNCATE || wcstr[conv-1]=='\0'))
else if(conv==size && count==MSVCRT__TRUNCATE && wcstr[conv-1]!='\0') {
wcstr[conv-1] = '\0';
else {
err = MSVCRT_STRUNCATE;
}else if(conv==size && wcstr[conv-1]!='\0') {
MSVCRT_INVALID_PMT("wcstr[size] is too small", MSVCRT_ERANGE);
if(size)
wcstr[0] = '\0';
@ -2458,7 +2460,7 @@ int CDECL MSVCRT__mbstowcs_s_l(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr,
if(ret)
*ret = conv;
return 0;
return err;
}
/*********************************************************************

View File

@ -2080,6 +2080,11 @@ static void test_mbstowcs(void)
return;
}
err = pmbstowcs_s(&ret, wOut, 1, mSimple, _TRUNCATE);
ok(err == STRUNCATE, "err = %d\n", err);
ok(ret == 1, "mbstowcs_s did not return 0\n");
ok(!wOut[0], "wOut[0] = %d\n", wOut[0]);
err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
ok(err == 0, "err = %d\n", err);
ok(ret == 5, "mbstowcs_s did not return 5\n");