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, ...@@ -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 count, MSVCRT__locale_t locale)
{ {
MSVCRT_size_t conv; MSVCRT_size_t conv;
int err = 0;
if(!wcstr && !size) { if(!wcstr && !size) {
conv = MSVCRT__mbstowcs_l(NULL, mbstr, 0, locale); 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, ...@@ -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); conv = MSVCRT__mbstowcs_l(wcstr, mbstr, conv, locale);
if(conv<size) if(conv<size)
wcstr[conv++] = '\0'; 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'; 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); MSVCRT_INVALID_PMT("wcstr[size] is too small", MSVCRT_ERANGE);
if(size) if(size)
wcstr[0] = '\0'; wcstr[0] = '\0';
...@@ -2458,7 +2460,7 @@ int CDECL MSVCRT__mbstowcs_s_l(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr, ...@@ -2458,7 +2460,7 @@ int CDECL MSVCRT__mbstowcs_s_l(MSVCRT_size_t *ret, MSVCRT_wchar_t *wcstr,
if(ret) if(ret)
*ret = conv; *ret = conv;
return 0; return err;
} }
/********************************************************************* /*********************************************************************
......
...@@ -2080,6 +2080,11 @@ static void test_mbstowcs(void) ...@@ -2080,6 +2080,11 @@ static void test_mbstowcs(void)
return; 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); err = pmbstowcs_s(&ret, wOut, 6, mSimple, _TRUNCATE);
ok(err == 0, "err = %d\n", err); ok(err == 0, "err = %d\n", err);
ok(ret == 5, "mbstowcs_s did not return 5\n"); 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