Commit 9ade30d0 authored by Dmitry Timoshkov's avatar Dmitry Timoshkov Committed by Alexandre Julliard

msvcrt: Fix handling of dst == src in wcscpy_s.

parent 92a5299b
......@@ -1020,6 +1020,11 @@ static void test_wcscpy_s(void)
ok(ret == 0, "expected 0 got %d\n", ret);
ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
/* dest == source */
ret = p_wcscpy_s(szDest, 18, szDest);
ok(ret == 0, "expected 0 got %d\n", ret);
ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
/* Copy smaller buffer size */
errno = EBADF;
szDest[0] = 'A';
......
......@@ -2041,16 +2041,21 @@ INT CDECL MSVCRT_wcscpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, con
if(!MSVCRT_CHECK_PMT(wcDest)) return MSVCRT_EINVAL;
if(!MSVCRT_CHECK_PMT(numElement)) return MSVCRT_EINVAL;
wcDest[0] = 0;
if(!MSVCRT_CHECK_PMT(wcSrc)) return MSVCRT_EINVAL;
if(!MSVCRT_CHECK_PMT(wcSrc))
{
wcDest[0] = 0;
return MSVCRT_EINVAL;
}
size = strlenW(wcSrc) + 1;
if(!MSVCRT_CHECK_PMT_ERR(size <= numElement, MSVCRT_ERANGE))
{
wcDest[0] = 0;
return MSVCRT_ERANGE;
}
memcpy( wcDest, wcSrc, size*sizeof(WCHAR) );
memmove( wcDest, wcSrc, size*sizeof(WCHAR) );
return 0;
}
......
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