shell32: Avoid zero length allocations when converting path in ExtractIconA() (Valgrind).

Signed-off-by: Nikolay Sivov <nsivov@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Nikolay Sivov 2017-06-05 02:10:28 +03:00 committed by Alexandre Julliard
parent 58adb553e4
commit 1a5561c0cf
2 changed files with 22 additions and 8 deletions

View File

@ -846,17 +846,16 @@ HICON WINAPI DuplicateIcon( HINSTANCE hInstance, HICON hIcon)
/*************************************************************************
* ExtractIconA [SHELL32.@]
*/
HICON WINAPI ExtractIconA(HINSTANCE hInstance, LPCSTR lpszFile, UINT nIconIndex)
{
HICON WINAPI ExtractIconA(HINSTANCE hInstance, const char *file, UINT nIconIndex)
{
WCHAR *fileW;
HICON ret;
INT len = MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, NULL, 0);
LPWSTR lpwstrFile = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
TRACE("%p %s %d\n", hInstance, lpszFile, nIconIndex);
TRACE("%p %s %d\n", hInstance, debugstr_a(file), nIconIndex);
MultiByteToWideChar(CP_ACP, 0, lpszFile, -1, lpwstrFile, len);
ret = ExtractIconW(hInstance, lpwstrFile, nIconIndex);
HeapFree(GetProcessHeap(), 0, lpwstrFile);
fileW = strdupAtoW(file);
ret = ExtractIconW(hInstance, fileW, nIconIndex);
HeapFree(GetProcessHeap(), 0, fileW);
return ret;
}

View File

@ -236,4 +236,19 @@ static inline WCHAR *strdupW(const WCHAR *src)
return dest;
}
static inline WCHAR *strdupAtoW(const char *str)
{
WCHAR *ret;
DWORD len;
if (!str) return NULL;
len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0);
ret = HeapAlloc(GetProcessHeap(), 0, len * sizeof(WCHAR));
if (ret)
MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len);
return ret;
}
#endif