Commit c0a1eff7 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

shell32/shelllink: Fix NULL path handling in SetIconLocation().

parent d8249c63
...@@ -1464,19 +1464,22 @@ static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA *iface, LPSTR ps ...@@ -1464,19 +1464,22 @@ static HRESULT WINAPI IShellLinkA_fnGetIconLocation(IShellLinkA *iface, LPSTR ps
return S_OK; return S_OK;
} }
static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA *iface, LPCSTR pszIconPath, static HRESULT WINAPI IShellLinkA_fnSetIconLocation(IShellLinkA *iface, LPCSTR path, INT icon)
INT iIcon)
{ {
IShellLinkImpl *This = impl_from_IShellLinkA(iface); IShellLinkImpl *This = impl_from_IShellLinkA(iface);
WCHAR *pathW; WCHAR *pathW = NULL;
HRESULT hr; HRESULT hr;
TRACE("(%p)->(path=%s iicon=%u)\n",This, pszIconPath, iIcon); TRACE("(%p)->(path=%s icon=%u)\n", This, debugstr_a(path), icon);
pathW = heap_strdupAtoW(pszIconPath); if (path)
if (!pathW) return E_OUTOFMEMORY; {
pathW = heap_strdupAtoW(path);
if (!pathW)
return E_OUTOFMEMORY;
}
hr = IShellLinkW_SetIconLocation(&This->IShellLinkW_iface, pathW, iIcon); hr = IShellLinkW_SetIconLocation(&This->IShellLinkW_iface, path ? pathW : NULL, icon);
heap_free(pathW); heap_free(pathW);
return hr; return hr;
...@@ -1927,19 +1930,24 @@ static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR ...@@ -1927,19 +1930,24 @@ static HRESULT WINAPI IShellLinkW_fnGetIconLocation(IShellLinkW * iface, LPWSTR
return S_OK; return S_OK;
} }
static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, LPCWSTR pszIconPath,INT iIcon) static HRESULT WINAPI IShellLinkW_fnSetIconLocation(IShellLinkW * iface, const WCHAR *path, INT icon)
{ {
IShellLinkImpl *This = impl_from_IShellLinkW(iface); IShellLinkImpl *This = impl_from_IShellLinkW(iface);
TRACE("(%p)->(path=%s iicon=%u)\n",This, debugstr_w(pszIconPath), iIcon); TRACE("(%p)->(path=%s icon=%u)\n", This, debugstr_w(path), icon);
heap_free(This->sIcoPath); heap_free(This->sIcoPath);
This->sIcoPath = heap_alloc((lstrlenW( pszIconPath )+1)*sizeof (WCHAR) ); if (path)
if ( !This->sIcoPath ) {
return E_OUTOFMEMORY; size_t len = (strlenW(path) + 1) * sizeof(WCHAR);
lstrcpyW( This->sIcoPath, pszIconPath ); This->sIcoPath = heap_alloc(len);
if (!This->sIcoPath)
This->iIcoNdx = iIcon; return E_OUTOFMEMORY;
memcpy(This->sIcoPath, path, len);
}
else
This->sIcoPath = NULL;
This->iIcoNdx = icon;
This->bDirty = TRUE; This->bDirty = TRUE;
return S_OK; return S_OK;
......
...@@ -973,6 +973,7 @@ static void test_shdefextracticon(void) ...@@ -973,6 +973,7 @@ static void test_shdefextracticon(void)
static void test_GetIconLocation(void) static void test_GetIconLocation(void)
{ {
IShellLinkW *slW;
IShellLinkA *sl; IShellLinkA *sl;
const char *str; const char *str;
char buffer[INFOTIPSIZE], mypath[MAX_PATH]; char buffer[INFOTIPSIZE], mypath[MAX_PATH];
...@@ -1026,8 +1027,34 @@ static void test_GetIconLocation(void) ...@@ -1026,8 +1027,34 @@ static void test_GetIconLocation(void)
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i); r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r); ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(lstrcmpiA(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer); ok(lstrcmpiA(buffer,str) == 0, "GetIconLocation returned '%s'\n", buffer);
ok(i == 0xbabecafe, "GetIconLocation returned %d'\n", i); ok(i == 0xbabecafe, "GetIconLocation returned %#x.\n", i);
r = IShellLinkA_SetIconLocation(sl, NULL, 0xcafefe);
ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
i = 0xdeadbeef;
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(!*buffer, "GetIconLocation returned '%s'\n", buffer);
ok(i == 0xcafefe, "GetIconLocation returned %#x.\n", i);
r = IShellLinkA_QueryInterface(sl, &IID_IShellLinkW, (void **)&slW);
ok(SUCCEEDED(r), "Failed to get IShellLinkW, hr %#x.\n", r);
str = "c:\\nonexistent\\file";
r = IShellLinkA_SetIconLocation(sl, str, 0xbabecafe);
ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
r = IShellLinkA_SetIconLocation(sl, NULL, 0xcafefe);
ok(r == S_OK, "SetIconLocation failed (0x%08x)\n", r);
i = 0xdeadbeef;
r = IShellLinkA_GetIconLocation(sl, buffer, sizeof(buffer), &i);
ok(r == S_OK, "GetIconLocation failed (0x%08x)\n", r);
ok(!*buffer, "GetIconLocation returned '%s'\n", buffer);
ok(i == 0xcafefe, "GetIconLocation returned %#x.\n", i);
IShellLinkW_Release(slW);
IShellLinkA_Release(sl); IShellLinkA_Release(sl);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment