shell32: Always NULL-terminate path in SHGetPathFromIDList.

This commit is contained in:
Juan Lang 2006-07-10 20:11:09 -07:00 committed by Alexandre Julliard
parent 4d3877b649
commit 961193bc5d
2 changed files with 12 additions and 2 deletions

View file

@ -1240,8 +1240,7 @@ BOOL WINAPI SHGetPathFromIDListA(LPCITEMIDLIST pidl, LPSTR pszPath)
BOOL bSuccess;
bSuccess = SHGetPathFromIDListW(pidl, wszPath);
if (bSuccess)
WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
WideCharToMultiByte(CP_ACP, 0, wszPath, -1, pszPath, MAX_PATH, NULL, NULL);
return bSuccess;
}
@ -1262,6 +1261,7 @@ BOOL WINAPI SHGetPathFromIDListW(LPCITEMIDLIST pidl, LPWSTR pszPath)
TRACE_(shell)("(pidl=%p,%p)\n", pidl, pszPath);
pdump(pidl);
*pszPath = '\0';
if (!pidl)
return FALSE;

View file

@ -771,6 +771,13 @@ static void test_SHGetPathFromIDList(void)
if(!pSHGetSpecialFolderPathW) return;
/* Calling SHGetPathFromIDList with no pidl should return the empty string */
wszPath[0] = 'a';
wszPath[1] = '\0';
result = SHGetPathFromIDListW(NULL, wszPath);
ok(!result, "Expected failure\n");
ok(!wszPath[0], "Expected empty string\n");
/* Calling SHGetPathFromIDList with an empty pidl should return the desktop folder's path. */
result = pSHGetSpecialFolderPathW(NULL, wszDesktop, CSIDL_DESKTOP, FALSE);
ok(result, "SHGetSpecialFolderPathW(CSIDL_DESKTOP) failed! Last error: %08lx\n", GetLastError());
@ -794,9 +801,12 @@ static void test_SHGetPathFromIDList(void)
}
SetLastError(0xdeadbeef);
wszPath[0] = 'a';
wszPath[1] = '\0';
result = SHGetPathFromIDListW(pidlMyComputer, wszPath);
ok (!result, "SHGetPathFromIDList succeeded where it shouldn't!\n");
ok (GetLastError()==0xdeadbeef, "SHGetPathFromIDList shouldn't set last error! Last error: %08lx\n", GetLastError());
ok (!wszPath[0], "Expected empty path\n");
if (result) {
IShellFolder_Release(psfDesktop);
return;