Robert Shearman : wininet: InternetCreateUrlW should return the number of bytes needed.

Alexandre Julliard julliard at wine.codeweavers.com
Tue Mar 21 13:21:12 CST 2006


Module: wine
Branch: refs/heads/master
Commit: 80e4fb597537b6db4f38a35783131d6f0906a02e
URL:    http://source.winehq.org/git/?p=wine.git;a=commit;h=80e4fb597537b6db4f38a35783131d6f0906a02e

Author: Robert Shearman <rob at codeweavers.com>
Date:   Tue Mar 21 13:44:36 2006 +0000

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 1a2638c..76f7b7e 100644
--- a/dlls/wininet/http.c
+++ b/dlls/wininet/http.c
@@ -2003,9 +2003,10 @@ static BOOL HTTP_HandleRedirect(LPWININE
             (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 42eb61d..cde3d52 100644
--- a/dlls/wininet/internet.c
+++ b/dlls/wininet/internet.c
@@ -3900,10 +3900,7 @@ static void convert_urlcomp_atow(LPURL_C
 /***********************************************************************
  *      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_COM
 
     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_COM
 /***********************************************************************
  *      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_COM
 
     if (!lpszUrl || *lpdwUrlLength < dwLen)
     {
-        *lpdwUrlLength = dwLen + 1; /* terminating null */
+        *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
         SetLastError(ERROR_INSUFFICIENT_BUFFER);
         return FALSE;
     }




More information about the wine-cvs mailing list