Commit 47217f59 authored by Piotr Caban's avatar Piotr Caban Committed by Alexandre Julliard

msvcrt: Fix _mbstowcs_s_l return value on truncate.

parent a9c4b309
......@@ -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;
}
/*********************************************************************
......
......@@ -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");
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment