Commit 8b661a18 authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

shell32: Stop using fixed size buffers for display names.

parent 3e2559b9
...@@ -66,14 +66,14 @@ typedef struct { ...@@ -66,14 +66,14 @@ typedef struct {
IDispatch *application; IDispatch *application;
IShellFolder2 *folder; IShellFolder2 *folder;
PIDLIST_ABSOLUTE pidl; PIDLIST_ABSOLUTE pidl;
WCHAR path[MAX_PATH]; BSTR path;
} FolderImpl; } FolderImpl;
typedef struct { typedef struct {
FolderItems3 FolderItems3_iface; FolderItems3 FolderItems3_iface;
LONG ref; LONG ref;
FolderImpl *folder; FolderImpl *folder;
WCHAR **item_names; BSTR *item_names;
LONG item_count; LONG item_count;
} FolderItemsImpl; } FolderItemsImpl;
...@@ -1030,7 +1030,7 @@ static ULONG WINAPI FolderItemsImpl_Release(FolderItems3 *iface) ...@@ -1030,7 +1030,7 @@ static ULONG WINAPI FolderItemsImpl_Release(FolderItems3 *iface)
{ {
Folder3_Release(&This->folder->Folder3_iface); Folder3_Release(&This->folder->Folder3_iface);
for (i = 0; i < This->item_count; i++) for (i = 0; i < This->item_count; i++)
HeapFree(GetProcessHeap(), 0, This->item_names[i]); SysFreeString(This->item_names[i]);
HeapFree(GetProcessHeap(), 0, This->item_names); HeapFree(GetProcessHeap(), 0, This->item_names);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
} }
...@@ -1132,7 +1132,7 @@ static HRESULT WINAPI FolderItemsImpl_get_Parent(FolderItems3 *iface, IDispatch ...@@ -1132,7 +1132,7 @@ static HRESULT WINAPI FolderItemsImpl_get_Parent(FolderItems3 *iface, IDispatch
static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, FolderItem **item) static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, FolderItem **item)
{ {
FolderItemsImpl *This = impl_from_FolderItems(iface); FolderItemsImpl *This = impl_from_FolderItems(iface);
WCHAR buffW[MAX_PATH], *display_name; BSTR display_name = NULL;
HRESULT hr; HRESULT hr;
TRACE("(%p,%s,%p)\n", iface, debugstr_variant(&index), item); TRACE("(%p,%s,%p)\n", iface, debugstr_variant(&index), item);
...@@ -1152,7 +1152,7 @@ static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, F ...@@ -1152,7 +1152,7 @@ static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, F
if (V_I4(&index) >= This->item_count || V_I4(&index) < 0) if (V_I4(&index) >= This->item_count || V_I4(&index) < 0)
return S_FALSE; return S_FALSE;
display_name = This->item_names[V_I4(&index)]; display_name = SysAllocString(This->item_names[V_I4(&index)]);
break; break;
case VT_BSTR: case VT_BSTR:
...@@ -1167,15 +1167,13 @@ static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, F ...@@ -1167,15 +1167,13 @@ static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, F
NULL, &pidl, NULL))) NULL, &pidl, NULL)))
return S_FALSE; return S_FALSE;
IShellFolder2_GetDisplayNameOf(This->folder->folder, pidl, SHGDN_FORPARSING, &strret); if (IShellFolder2_GetDisplayNameOf(This->folder->folder, pidl, SHGDN_FORPARSING, &strret) == S_OK)
StrRetToBufW(&strret, NULL, buffW, sizeof(buffW)/sizeof(*buffW)); StrRetToBSTR(&strret, pidl, &display_name);
ILFree(pidl); ILFree(pidl);
display_name = buffW;
break; break;
} }
case VT_ERROR: case VT_ERROR:
return FolderItem_Constructor(This->folder, NULL, item); break;
default: default:
FIXME("Index type %d not handled.\n", V_VT(&index)); FIXME("Index type %d not handled.\n", V_VT(&index));
...@@ -1184,7 +1182,9 @@ static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, F ...@@ -1184,7 +1182,9 @@ static HRESULT WINAPI FolderItemsImpl_Item(FolderItems3 *iface, VARIANT index, F
return E_NOTIMPL; return E_NOTIMPL;
} }
return FolderItem_Constructor(This->folder, display_name, item); hr = FolderItem_Constructor(This->folder, display_name, item);
SysFreeString(display_name);
return hr;
} }
static HRESULT WINAPI FolderItemsImpl__NewEnum(FolderItems3 *iface, IUnknown **ppunk) static HRESULT WINAPI FolderItemsImpl__NewEnum(FolderItems3 *iface, IUnknown **ppunk)
...@@ -1313,7 +1313,7 @@ static HRESULT FolderItems_Constructor(FolderImpl *folder, FolderItems **ret) ...@@ -1313,7 +1313,7 @@ static HRESULT FolderItems_Constructor(FolderImpl *folder, FolderItems **ret)
ULONG fetched; ULONG fetched;
pidls = HeapAlloc(GetProcessHeap(), 0, This->item_count * sizeof(*pidls)); pidls = HeapAlloc(GetProcessHeap(), 0, This->item_count * sizeof(*pidls));
This->item_names = HeapAlloc(GetProcessHeap(), 0, This->item_count * sizeof(*This->item_names)); This->item_names = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, This->item_count * sizeof(*This->item_names));
if (!pidls || !This->item_names) if (!pidls || !This->item_names)
{ {
...@@ -1329,13 +1329,10 @@ static HRESULT FolderItems_Constructor(FolderImpl *folder, FolderItems **ret) ...@@ -1329,13 +1329,10 @@ static HRESULT FolderItems_Constructor(FolderImpl *folder, FolderItems **ret)
for (i = 0; i < This->item_count; i++) for (i = 0; i < This->item_count; i++)
{ {
WCHAR buffW[MAX_PATH];
STRRET strret; STRRET strret;
IShellFolder2_GetDisplayNameOf(folder->folder, pidls[i], SHGDN_FORPARSING, &strret); if (IShellFolder2_GetDisplayNameOf(folder->folder, pidls[i], SHGDN_FORPARSING, &strret) == S_OK)
StrRetToBufW(&strret, NULL, buffW, sizeof(buffW)/sizeof(*buffW)); StrRetToBSTR(&strret, pidls[i], &This->item_names[i]);
This->item_names[i] = strdupW(buffW);
ILFree(pidls[i]); ILFree(pidls[i]);
} }
...@@ -1397,6 +1394,7 @@ static ULONG WINAPI FolderImpl_Release(Folder3 *iface) ...@@ -1397,6 +1394,7 @@ static ULONG WINAPI FolderImpl_Release(Folder3 *iface)
if (!ref) if (!ref)
{ {
ILFree(This->pidl); ILFree(This->pidl);
SysFreeString(This->path);
IShellFolder2_Release(This->folder); IShellFolder2_Release(This->folder);
IDispatch_Release(This->application); IDispatch_Release(This->application);
HeapFree(GetProcessHeap(), 0, This); HeapFree(GetProcessHeap(), 0, This);
...@@ -1463,7 +1461,6 @@ static HRESULT WINAPI FolderImpl_get_Title(Folder3 *iface, BSTR *title) ...@@ -1463,7 +1461,6 @@ static HRESULT WINAPI FolderImpl_get_Title(Folder3 *iface, BSTR *title)
FolderImpl *This = impl_from_Folder(iface); FolderImpl *This = impl_from_Folder(iface);
PCUITEMID_CHILD last_part; PCUITEMID_CHILD last_part;
IShellFolder2 *parent; IShellFolder2 *parent;
WCHAR buffW[MAX_PATH];
SHELLDETAILS sd; SHELLDETAILS sd;
HRESULT hr; HRESULT hr;
...@@ -1479,10 +1476,7 @@ static HRESULT WINAPI FolderImpl_get_Title(Folder3 *iface, BSTR *title) ...@@ -1479,10 +1476,7 @@ static HRESULT WINAPI FolderImpl_get_Title(Folder3 *iface, BSTR *title)
if (FAILED(hr)) if (FAILED(hr))
return hr; return hr;
StrRetToBufW(&sd.str, NULL, buffW, sizeof(buffW)/sizeof(buffW[0])); return StrRetToBSTR(&sd.str, last_part, title);
*title = SysAllocString(buffW);
return *title ? S_OK : E_OUTOFMEMORY;
} }
static HRESULT WINAPI FolderImpl_get_Application(Folder3 *iface, IDispatch **disp) static HRESULT WINAPI FolderImpl_get_Application(Folder3 *iface, IDispatch **disp)
...@@ -1529,10 +1523,10 @@ static HRESULT WINAPI FolderImpl_Items(Folder3 *iface, FolderItems **ppid) ...@@ -1529,10 +1523,10 @@ static HRESULT WINAPI FolderImpl_Items(Folder3 *iface, FolderItems **ppid)
static HRESULT WINAPI FolderImpl_ParseName(Folder3 *iface, BSTR name, FolderItem **item) static HRESULT WINAPI FolderImpl_ParseName(Folder3 *iface, BSTR name, FolderItem **item)
{ {
FolderImpl *This = impl_from_Folder(iface); FolderImpl *This = impl_from_Folder(iface);
WCHAR pathW[MAX_PATH];
LPITEMIDLIST pidl; LPITEMIDLIST pidl;
STRRET strret; STRRET strret;
HRESULT hr; HRESULT hr;
BSTR path;
TRACE("(%p,%s,%p)\n", iface, debugstr_w(name), item); TRACE("(%p,%s,%p)\n", iface, debugstr_w(name), item);
...@@ -1541,14 +1535,16 @@ static HRESULT WINAPI FolderImpl_ParseName(Folder3 *iface, BSTR name, FolderItem ...@@ -1541,14 +1535,16 @@ static HRESULT WINAPI FolderImpl_ParseName(Folder3 *iface, BSTR name, FolderItem
if (FAILED(IShellFolder2_ParseDisplayName(This->folder, NULL, NULL, name, NULL, &pidl, NULL))) if (FAILED(IShellFolder2_ParseDisplayName(This->folder, NULL, NULL, name, NULL, &pidl, NULL)))
return S_FALSE; return S_FALSE;
hr = IShellFolder2_GetDisplayNameOf(This->folder, pidl, SHGDN_FORPARSING, &strret); if ((hr = IShellFolder2_GetDisplayNameOf(This->folder, pidl, SHGDN_FORPARSING, &strret)) == S_OK)
StrRetToBSTR(&strret, pidl, &path);
ILFree(pidl); ILFree(pidl);
if (FAILED(hr)) if (FAILED(hr))
return S_FALSE; return S_FALSE;
StrRetToBufW(&strret, NULL, pathW, sizeof(pathW)/sizeof(*pathW)); hr = FolderItem_Constructor(This, path, item);
SysFreeString(path);
return FolderItem_Constructor(This, pathW, item); return hr;
} }
static HRESULT WINAPI FolderImpl_NewFolder(Folder3 *iface, BSTR bName, static HRESULT WINAPI FolderImpl_NewFolder(Folder3 *iface, BSTR bName,
...@@ -1686,7 +1682,7 @@ static HRESULT Folder_Constructor(IShellFolder2 *folder, LPITEMIDLIST pidl, Fold ...@@ -1686,7 +1682,7 @@ static HRESULT Folder_Constructor(IShellFolder2 *folder, LPITEMIDLIST pidl, Fold
hr = SHBindToParent(pidl, &IID_IShellFolder2, (void **)&parent, &last_part); hr = SHBindToParent(pidl, &IID_IShellFolder2, (void **)&parent, &last_part);
IShellFolder2_GetDisplayNameOf(parent, last_part, SHGDN_FORPARSING, &strret); IShellFolder2_GetDisplayNameOf(parent, last_part, SHGDN_FORPARSING, &strret);
StrRetToBufW(&strret, NULL, This->path, sizeof(This->path)/sizeof(*This->path)); StrRetToBSTR(&strret, last_part, &This->path);
IShellFolder2_Release(parent); IShellFolder2_Release(parent);
IShellDispatch_Constructor(NULL, &IID_IDispatch, (void **)&This->application); IShellDispatch_Constructor(NULL, &IID_IDispatch, (void **)&This->application);
......
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