diff --git a/dlls/shlwapi/url.c b/dlls/shlwapi/url.c index ae2f408320a..bb5e633c237 100644 --- a/dlls/shlwapi/url.c +++ b/dlls/shlwapi/url.c @@ -42,6 +42,21 @@ HRESULT WINAPI MLBuildResURLW(LPCWSTR,HMODULE,DWORD,LPCWSTR,LPWSTR,DWORD); WINE_DEFAULT_DEBUG_CHANNEL(shell); +static inline WCHAR *heap_strdupAtoW(const char *str) +{ + LPWSTR ret = NULL; + + if(str) { + DWORD len; + + len = MultiByteToWideChar(CP_ACP, 0, str, -1, NULL, 0); + ret = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); + MultiByteToWideChar(CP_ACP, 0, str, -1, ret, len); + } + + return ret; +} + /* The following schemes were identified in the native version of * SHLWAPI.DLL version 5.50 */ @@ -234,7 +249,6 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, { LPWSTR url, canonical; HRESULT ret; - DWORD len; TRACE("(%s, %p, %p, 0x%08x) *pcchCanonicalized: %d\n", debugstr_a(pszUrl), pszCanonicalized, pcchCanonicalized, dwFlags, pcchCanonicalized ? *pcchCanonicalized : -1); @@ -242,8 +256,7 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, if(!pszUrl || !pszCanonicalized || !pcchCanonicalized || !*pcchCanonicalized) return E_INVALIDARG; - len = strlen(pszUrl)+1; - url = HeapAlloc(GetProcessHeap(), 0, len*sizeof(WCHAR)); + url = heap_strdupAtoW(pszUrl); canonical = HeapAlloc(GetProcessHeap(), 0, *pcchCanonicalized*sizeof(WCHAR)); if(!url || !canonical) { HeapFree(GetProcessHeap(), 0, url); @@ -251,13 +264,12 @@ HRESULT WINAPI UrlCanonicalizeA(LPCSTR pszUrl, LPSTR pszCanonicalized, return E_OUTOFMEMORY; } - MultiByteToWideChar(0, 0, pszUrl, -1, url, len); - ret = UrlCanonicalizeW(url, canonical, pcchCanonicalized, dwFlags); if(ret == S_OK) WideCharToMultiByte(0, 0, canonical, -1, pszCanonicalized, *pcchCanonicalized+1, 0, 0); + HeapFree(GetProcessHeap(), 0, url); HeapFree(GetProcessHeap(), 0, canonical); return ret; }