msvcrt: Fix wcsncpy_s implementation.

This commit is contained in:
Piotr Caban 2011-10-04 23:03:03 +02:00 committed by Alexandre Julliard
parent 50110d4bbd
commit 8df606fea4
2 changed files with 37 additions and 2 deletions

View File

@ -61,6 +61,7 @@ static int (__cdecl *pstrcat_s)(char *dst, size_t len, const char *src);
static int (__cdecl *p_mbsnbcat_s)(unsigned char *dst, size_t size, const unsigned char *src, size_t count);
static int (__cdecl *p_mbsnbcpy_s)(unsigned char * dst, size_t size, const unsigned char * src, size_t count);
static int (__cdecl *p_wcscpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc);
static int (__cdecl *p_wcsncpy_s)(wchar_t *wcDest, size_t size, const wchar_t *wcSrc, size_t count);
static int (__cdecl *p_wcsncat_s)(wchar_t *dst, size_t elem, const wchar_t *src, size_t count);
static int (__cdecl *p_wcsupr_s)(wchar_t *str, size_t size);
static size_t (__cdecl *p_strnlen)(const char *, size_t);
@ -615,7 +616,7 @@ static void test_wcscpy_s(void)
if(!p_wcscpy_s)
{
skip("wcscpy_s not found\n");
win_skip("wcscpy_s not found\n");
return;
}
@ -648,6 +649,39 @@ static void test_wcscpy_s(void)
ret = p_wcscpy_s(szDestShort, 8, szLongText);
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
if(!p_wcsncpy_s)
{
win_skip("wcsncpy_s not found\n");
return;
}
ret = p_wcsncpy_s(NULL, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
ok(ret == EINVAL, "p_wcsncpy_s expect EINVAL got %d\n", ret);
szDest[0] = 'A';
ret = p_wcsncpy_s(szDest, 18, NULL, 1);
ok(ret == EINVAL, "expected EINVAL got %d\n", ret);
ok(szDest[0] == 0, "szDest[0] not 0\n");
szDest[0] = 'A';
ret = p_wcsncpy_s(szDest, 18, NULL, 0);
ok(ret == 0, "expected ERROR_SUCCESS got %d\n", ret);
ok(szDest[0] == 0, "szDest[0] not 0\n");
szDest[0] = 'A';
ret = p_wcsncpy_s(szDest, 0, szLongText, sizeof(szLongText)/sizeof(WCHAR));
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
ok(szDest[0] == 0 || ret == EINVAL, "szDest[0] not 0\n");
ret = p_wcsncpy_s(szDest, 18, szLongText, sizeof(szLongText)/sizeof(WCHAR));
ok(ret == 0, "expected 0 got %d\n", ret);
ok(lstrcmpW(szDest, szLongText) == 0, "szDest != szLongText\n");
szDest[0] = 'A';
ret = p_wcsncpy_s(szDestShort, 8, szLongText, sizeof(szLongText)/sizeof(WCHAR));
ok(ret == ERANGE || ret == EINVAL, "expected ERANGE/EINVAL got %d\n", ret);
ok(szDestShort[0] == 0, "szDestShort[0] not 0\n");
}
static void test__wcsupr_s(void)
@ -2027,6 +2061,7 @@ START_TEST(string)
p_mbsnbcat_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcat_s" );
p_mbsnbcpy_s = (void *)GetProcAddress( hMsvcrt,"_mbsnbcpy_s" );
p_wcscpy_s = (void *)GetProcAddress( hMsvcrt,"wcscpy_s" );
p_wcsncpy_s = (void *)GetProcAddress( hMsvcrt,"wcsncpy_s" );
p_wcsncat_s = (void *)GetProcAddress( hMsvcrt,"wcsncat_s" );
p_wcsupr_s = (void *)GetProcAddress( hMsvcrt,"_wcsupr_s" );
p_strnlen = (void *)GetProcAddress( hMsvcrt,"strnlen" );

View File

@ -1210,7 +1210,7 @@ INT CDECL MSVCRT_wcsncpy_s( MSVCRT_wchar_t* wcDest, MSVCRT_size_t numElement, co
if (!wcSrc)
{
return MSVCRT_EINVAL;
return count ? MSVCRT_EINVAL : 0;
}
size = min(strlenW(wcSrc), count);