Jacek Caban : wininet: Added new heap_strndupAtoW helper and use it in HttpAddRequestHeadersA.

Alexandre Julliard julliard at wine.codeweavers.com
Wed Apr 27 10:45:43 CDT 2016


Module: wine
Branch: master
Commit: d282a64280f3e147f09adae9e3e3152b1d20dbb5
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=d282a64280f3e147f09adae9e3e3152b1d20dbb5

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Wed Apr 27 14:18:12 2016 +0200

wininet: Added new heap_strndupAtoW helper and use it in HttpAddRequestHeadersA.

Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/wininet/http.c     | 14 +++++---------
 dlls/wininet/internet.h | 19 +++++++++++++++++++
 2 files changed, 24 insertions(+), 9 deletions(-)

diff --git a/dlls/wininet/http.c b/dlls/wininet/http.c
index bdc659d..ef0b36e 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 8c3a1f1..eb3a023 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;




More information about the wine-cvs mailing list