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).
This commit is contained in:
Robert Shearman 2006-03-21 13:44:36 +00:00 committed by Alexandre Julliard
parent c307f4990f
commit 80e4fb5975
2 changed files with 23 additions and 7 deletions

View File

@ -2003,9 +2003,10 @@ static BOOL HTTP_HandleRedirect(LPWININETHTTPREQW lpwhr, LPCWSTR lpszUrl, LPCWST
(GetLastError() != ERROR_INSUFFICIENT_BUFFER)) (GetLastError() != ERROR_INSUFFICIENT_BUFFER))
return FALSE; return FALSE;
url_length++; /* for nul terminating character */ orig_url = HeapAlloc(GetProcessHeap(), 0, url_length);
orig_url = HeapAlloc(GetProcessHeap(), 0, url_length * sizeof(WCHAR));
/* convert from bytes to characters */
url_length = url_length / sizeof(WCHAR) - 1;
if (!InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length)) if (!InternetCreateUrlW(&urlComponents, 0, orig_url, &url_length))
{ {
HeapFree(GetProcessHeap(), 0, orig_url); HeapFree(GetProcessHeap(), 0, orig_url);

View File

@ -3900,10 +3900,7 @@ static void convert_urlcomp_atow(LPURL_COMPONENTSA lpUrlComponents, LPURL_COMPON
/*********************************************************************** /***********************************************************************
* InternetCreateUrlA (WININET.@) * InternetCreateUrlA (WININET.@)
* *
* RETURNS * See InternetCreateUrlW.
* TRUE on success
* FALSE on failure
*
*/ */
BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags, BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
LPSTR lpszUrl, LPDWORD lpdwUrlLength) LPSTR lpszUrl, LPDWORD lpdwUrlLength)
@ -3930,6 +3927,9 @@ BOOL WINAPI InternetCreateUrlA(LPURL_COMPONENTSA lpUrlComponents, DWORD dwFlags,
ret = InternetCreateUrlW(&urlCompW, dwFlags, urlW, lpdwUrlLength); 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 /* on success, lpdwUrlLength points to the size of urlW in WCHARS
* minus one, so add one to leave room for NULL terminator * 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.@) * 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 * RETURNS
* TRUE on success * TRUE on success
* FALSE on failure * FALSE on failure
@ -3980,7 +3995,7 @@ BOOL WINAPI InternetCreateUrlW(LPURL_COMPONENTSW lpUrlComponents, DWORD dwFlags,
if (!lpszUrl || *lpdwUrlLength < dwLen) if (!lpszUrl || *lpdwUrlLength < dwLen)
{ {
*lpdwUrlLength = dwLen + 1; /* terminating null */ *lpdwUrlLength = (dwLen + 1) * sizeof(WCHAR);
SetLastError(ERROR_INSUFFICIENT_BUFFER); SetLastError(ERROR_INSUFFICIENT_BUFFER);
return FALSE; return FALSE;
} }