diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c index bdc659dfb65..ef0b36e1037 100644 --- a/dlls/wininet/http.c +++ b/dlls/wininet/http.c @@ -1376,21 +1376,17 @@ BOOL WINAPI HttpAddRequestHeadersW(HINTERNET hHttpRequest, BOOL WINAPI HttpAddRequestHeadersA(HINTERNET hHttpRequest, LPCSTR lpszHeader, DWORD dwHeaderLength, DWORD dwModifier) { - DWORD len; - LPWSTR hdr; + WCHAR *headers = NULL; BOOL r; TRACE("%p, %s, %i, %i\n", hHttpRequest, debugstr_an(lpszHeader, dwHeaderLength), dwHeaderLength, dwModifier); - len = MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, NULL, 0 ); - hdr = heap_alloc(len*sizeof(WCHAR)); - MultiByteToWideChar( CP_ACP, 0, lpszHeader, dwHeaderLength, hdr, len ); - if( dwHeaderLength != ~0U ) - dwHeaderLength = len; + if(lpszHeader) + headers = heap_strndupAtoW(lpszHeader, dwHeaderLength, &dwHeaderLength); - r = HttpAddRequestHeadersW( hHttpRequest, hdr, dwHeaderLength, dwModifier ); + r = HttpAddRequestHeadersW(hHttpRequest, headers, dwHeaderLength, dwModifier); - heap_free( hdr ); + heap_free(headers); return r; } diff --git a/dlls/wininet/internet.h b/dlls/wininet/internet.h index 8c3a1f1f3c2..eb3a0238887 100644 --- a/dlls/wininet/internet.h +++ b/dlls/wininet/internet.h @@ -166,6 +166,25 @@ static inline LPWSTR heap_strndupW(LPCWSTR str, UINT max_len) return ret; } +static inline WCHAR *heap_strndupAtoW(const char *str, int len_a, DWORD *len_w) +{ + WCHAR *ret = NULL; + + if(str) { + size_t len; + if(len_a < 0) len_a = strlen(str); + len = MultiByteToWideChar(CP_ACP, 0, str, len_a, NULL, 0); + ret = heap_alloc((len+1)*sizeof(WCHAR)); + if(ret) { + MultiByteToWideChar(CP_ACP, 0, str, len_a, ret, len); + ret[len] = 0; + *len_w = len; + } + } + + return ret; +} + static inline WCHAR *heap_strdupAtoW(const char *str) { LPWSTR ret = NULL;