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

Signed-off-by: Dmitry Timoshkov <dmitry@baikal.ru>
Signed-off-by: Piotr Caban <piotr@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Dmitry Timoshkov 2019-06-24 11:49:34 +08:00 committed by Alexandre Julliard
parent 92a5299b1d
commit 9ade30d0ce
2 changed files with 14 additions and 4 deletions

View file

@ -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';

View file

@ -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;
}