shlwapi: Fix StrCpyNW to deal with null inputs better, and don't use lstrcpynW.
This commit is contained in:
parent
e669ffe6e5
commit
93b3ba76f6
|
@ -507,23 +507,33 @@ LPWSTR WINAPI StrCpyW(LPWSTR lpszStr, LPCWSTR lpszSrc)
|
||||||
* Copy a string to another string, up to a maximum number of characters.
|
* Copy a string to another string, up to a maximum number of characters.
|
||||||
*
|
*
|
||||||
* PARAMS
|
* PARAMS
|
||||||
* lpszStr [O] Destination string
|
* dst [O] Destination string
|
||||||
* lpszSrc [I] Source string
|
* src [I] Source string
|
||||||
* iLen [I] Maximum number of chars to copy
|
* count [I] Maximum number of chars to copy
|
||||||
*
|
*
|
||||||
* RETURNS
|
* RETURNS
|
||||||
* lpszStr.
|
* dst.
|
||||||
*/
|
*/
|
||||||
LPWSTR WINAPI StrCpyNW(LPWSTR lpszStr, LPCWSTR lpszSrc, int iLen)
|
LPWSTR WINAPI StrCpyNW(LPWSTR dst, LPCWSTR src, int count)
|
||||||
{
|
{
|
||||||
TRACE("(%p,%s,%i)\n", lpszStr, debugstr_w(lpszSrc), iLen);
|
LPWSTR d = dst;
|
||||||
|
LPCWSTR s = src;
|
||||||
|
|
||||||
lstrcpynW(lpszStr, lpszSrc, iLen);
|
TRACE("(%p,%s,%i)\n", dst, debugstr_w(src), count);
|
||||||
return lpszStr;
|
|
||||||
|
if (s)
|
||||||
|
{
|
||||||
|
while ((count > 1) && *s)
|
||||||
|
{
|
||||||
|
count--;
|
||||||
|
*d++ = *s++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (count) *d = 0;
|
||||||
|
|
||||||
|
return dst;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/*************************************************************************
|
/*************************************************************************
|
||||||
* SHLWAPI_StrStrHelperA
|
* SHLWAPI_StrStrHelperA
|
||||||
*
|
*
|
||||||
|
|
|
@ -863,6 +863,33 @@ static void test_StrXXX_overflows(void)
|
||||||
else
|
else
|
||||||
win_skip("StrCatBuffA() is not available\n");
|
win_skip("StrCatBuffA() is not available\n");
|
||||||
|
|
||||||
|
if (0)
|
||||||
|
{
|
||||||
|
/* crashes on XP */
|
||||||
|
StrCpyNW(wbuf, (LPCWSTR)0x1, 10);
|
||||||
|
StrCpyNW((LPWSTR)0x1, wstr1, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(wbuf, 0xbf, sizeof(wbuf));
|
||||||
|
expect_eq(StrCpyNW(wbuf, (LPCWSTR)0x1, 1), wbuf, PWCHAR, "%p");
|
||||||
|
expect_eq(wbuf[0], 0, WCHAR, "%x");
|
||||||
|
expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
|
||||||
|
|
||||||
|
memset(wbuf, 0xbf, sizeof(wbuf));
|
||||||
|
expect_eq(StrCpyNW(wbuf, 0, 10), wbuf, PWCHAR, "%p");
|
||||||
|
expect_eq(wbuf[0], 0, WCHAR, "%x");
|
||||||
|
expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
|
||||||
|
|
||||||
|
memset(wbuf, 0xbf, sizeof(wbuf));
|
||||||
|
expect_eq(StrCpyNW(wbuf, 0, 0), wbuf, PWCHAR, "%p");
|
||||||
|
expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
|
||||||
|
expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
|
||||||
|
|
||||||
|
memset(wbuf, 0xbf, sizeof(wbuf));
|
||||||
|
expect_eq(StrCpyNW(wbuf, wstr1, 0), wbuf, PWCHAR, "%p");
|
||||||
|
expect_eq(wbuf[0], (WCHAR)0xbfbf, WCHAR, "%x");
|
||||||
|
expect_eq(wbuf[1], (WCHAR)0xbfbf, WCHAR, "%x");
|
||||||
|
|
||||||
memset(wbuf, 0xbf, sizeof(wbuf));
|
memset(wbuf, 0xbf, sizeof(wbuf));
|
||||||
expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
|
expect_eq(StrCpyNW(wbuf, wstr1, 10), wbuf, PWCHAR, "%p");
|
||||||
expect_eq(wbuf[9], 0, WCHAR, "%x");
|
expect_eq(wbuf[9], 0, WCHAR, "%x");
|
||||||
|
|
Loading…
Reference in New Issue