Commit 384ece4d authored by Nikolay Sivov's avatar Nikolay Sivov Committed by Alexandre Julliard

comdlg32/itemdlg: Fix setting NULL file name (Coverity).

parent 92e9f440
......@@ -384,14 +384,12 @@ static UINT get_file_name(FileDialogImpl *This, LPWSTR *str)
static BOOL set_file_name(FileDialogImpl *This, LPCWSTR str)
{
HWND hwnd_edit = GetDlgItem(This->dlg_hwnd, IDC_FILENAME);
if(This->set_filename)
LocalFree(This->set_filename);
This->set_filename = StrDupW(str);
This->set_filename = str ? StrDupW(str) : NULL;
return SendMessageW(hwnd_edit, WM_SETTEXT, 0, (LPARAM)str);
return SetDlgItemTextW(This->dlg_hwnd, IDC_FILENAME, This->set_filename);
}
static void fill_filename_from_selection(FileDialogImpl *This)
......@@ -2608,10 +2606,8 @@ static HRESULT WINAPI IFileDialog2_fnGetFileName(IFileDialog2 *iface, LPWSTR *ps
return E_INVALIDARG;
*pszName = NULL;
if(get_file_name(This, pszName))
return S_OK;
else
return E_FAIL;
get_file_name(This, pszName);
return *pszName ? S_OK : E_FAIL;
}
static HRESULT WINAPI IFileDialog2_fnSetTitle(IFileDialog2 *iface, LPCWSTR pszTitle)
......
......@@ -797,6 +797,21 @@ static void test_basics(void)
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IFileOpenDialog_SetFileName(pfod, null);
ok(hr == S_OK, "got 0x%08x\n", hr);
filename = NULL;
hr = IFileOpenDialog_GetFileName(pfod, &filename);
ok(hr == S_OK, "Got 0x%08x\n", hr);
ok(!lstrcmpW(filename, null), "Strings do not match.\n");
CoTaskMemFree(filename);
hr = IFileOpenDialog_SetFileName(pfod, NULL);
ok(hr == S_OK, "got 0x%08x\n", hr);
filename = (void*)0xdeadbeef;
hr = IFileOpenDialog_GetFileName(pfod, &filename);
ok(hr == E_FAIL, "Got 0x%08x\n", hr);
ok(filename == NULL, "got %p.\n", filename);
hr = IFileOpenDialog_SetFileName(pfod, txt);
ok(hr == S_OK, "got 0x%08x\n", hr);
hr = IFileOpenDialog_GetFileName(pfod, &filename);
......
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