Signed-off-by: Dmitry Timoshkov dmitry@baikal.ru --- dlls/msvcrt/tests/string.c | 5 +++++ dlls/msvcrt/wcs.c | 13 +++++++++---- 2 files changed, 14 insertions(+), 4 deletions(-)
diff --git a/dlls/msvcrt/tests/string.c b/dlls/msvcrt/tests/string.c index 0f1ee47d17..da6478c1b1 100644 --- a/dlls/msvcrt/tests/string.c +++ b/dlls/msvcrt/tests/string.c @@ -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'; diff --git a/dlls/msvcrt/wcs.c b/dlls/msvcrt/wcs.c index e62ac25edc..6b8c7bbe0f 100644 --- a/dlls/msvcrt/wcs.c +++ b/dlls/msvcrt/wcs.c @@ -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; }