From 80e4fb597537b6db4f38a35783131d6f0906a02e Mon Sep 17 00:00:00 2001 From: Robert Shearman Date: Tue, 21 Mar 2006 13:44:36 +0000 Subject: [PATCH] wininet: InternetCreateUrlW should return the number of bytes needed. InternetCreateUrlW should return the number of bytes needed to store the URL, not the number of characters (reported by Sven Paschukat). --- dlls/wininet/http.c | 5 +++-- dlls/wininet/internet.c | 25 ++++++++++++++++++++----- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index 1a2638cfe65..76f7b7e8b3e 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -2003,9 +2003,10 @@ static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, LPCWST (GetLastError() != ERROR_INSUFFICIENT_BUFFER)) return FALSE; - url_length++; /* for nul terminating character */ - orig_url = HeapAlloc(GetProcessHeap(), 0, url_length * sizeof(WCHAR)); + orig_url = HeapAlloc(GetProcessHeap(), 0, url_length); + /* convert from bytes to characters */ + url_length = url_length / sizeof(WCHAR) - 1; if (!InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length)) { HeapFree(GetProcessHeap(), 0, orig_url); diff --git a/dlls/wininet/internet.c b/dlls/wininet/internet.c index 42eb61de1a8..cde3d521b06 100644 --- a/dlls/wininet/internet.c +++ b/dlls/wininet/internet.c @@ -3900,10 +3900,7 @@ static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPON /*********************************************************************** * InternetCreateUrlA (WININET.@) * - * RETURNS - * TRUE on success - * FALSE on failure - * + * See InternetCreateUrlW. */ BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags, LPSTR lpszUrl, LPDWORD lpdwUrlLength) @@ -3930,6 +3927,9 @@ BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags, ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength); + if (!ret && (GetLastError() == ERROR_INSUFFICIENT_BUFFER)) + *lpdwUrlLength /= sizeof(WCHAR); + /* on success, lpdwUrlLength points to the size of urlW in WCHARS * minus one, so add one to leave room for NULL terminator */ @@ -3950,6 +3950,21 @@ BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags, /*********************************************************************** * InternetCreateUrlW (WININET.@) * + * Creates a URL from its component parts. + * + * PARAMS + * lpUrlComponents [I] URL Components. + * dwFlags [I] Flags. See notes. + * lpszUrl [I] Buffer in which to store the created URL. + * lpdwUrlLength [I/O] On input, the length of the buffer pointed to by + * lpszUrl in characters. On output, the number of bytes + * required to store the URL including terminator. + * + * NOTES + * + * The dwFlags parameter can be zero or more of the following: + *|ICU_ESCAPE - Generates escape sequences for unsafe characters in the path and extra info of the URL. + * * RETURNS * TRUE on success * FALSE on failure @@ -3980,7 +3995,7 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags, if (!lpszUrl || *lpdwUrlLength < dwLen) { - *lpdwUrlLength = dwLen + 1; /* terminating null */ + *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR); SetLastError(ERROR_INSUFFICIENT_BUFFER); return FALSE; }