[SHLWAPI][SHLWAPI_APITEST] Optimize StrRetToStrW WSTR handling (#7513)

This avoids Alloc/Free while also matching the Windows behavior.
This commit is contained in:
Whindmar Saksit 2024-11-19 23:50:08 +01:00 committed by GitHub
parent e3c859ed96
commit 4d0a26db58
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 23 additions and 0 deletions

View File

@ -1635,8 +1635,14 @@ HRESULT WINAPI StrRetToStrW(LPSTRRET lpStrRet, const ITEMIDLIST *pidl, LPWSTR *p
switch (lpStrRet->uType)
{
case STRRET_WSTR:
#ifdef __REACTOS__
hRet = lpStrRet->u.pOleStr ? S_OK : E_FAIL;
*ppszName = lpStrRet->u.pOleStr;
lpStrRet->u.pOleStr = NULL; /* Windows does this, presumably in case someone calls SHFree */
#else
hRet = SHStrDupW(lpStrRet->u.pOleStr, ppszName);
CoTaskMemFree(lpStrRet->u.pOleStr);
#endif
break;
case STRRET_CSTR:

View File

@ -39,8 +39,25 @@ static void TEST_StrDupW(void)
LocalFree(ptrW);
}
static void TEST_StrRet(void)
{
LPWSTR input, output;
if (SUCCEEDED(SHStrDupW(L"Test", &input)))
{
STRRET strret;
strret.uType = STRRET_WSTR;
U(strret).pOleStr = input;
output = NULL;
ok_int(StrRetToStrW(&strret, NULL, &output), S_OK);
ok_ptr(U(strret).pOleStr, NULL);
ok_ptr(input, output);
CoTaskMemFree(output);
}
}
START_TEST(StrDup)
{
TEST_StrDupA();
TEST_StrDupW();
TEST_StrRet();
}