[PATCH 5/5] d3d11: Introduce a helper function to allocate arrays.

Henri Verbeet hverbeet at codeweavers.com
Tue May 24 12:46:45 CDT 2016


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/d3d11/d3d11_private.h | 7 +++++++
 dlls/d3d11/inputlayout.c   | 3 +--
 dlls/d3d11/shader.c        | 3 +--
 3 files changed, 9 insertions(+), 4 deletions(-)

diff --git a/dlls/d3d11/d3d11_private.h b/dlls/d3d11/d3d11_private.h
index b3638c3..77079bd 100644
--- a/dlls/d3d11/d3d11_private.h
+++ b/dlls/d3d11/d3d11_private.h
@@ -79,6 +79,13 @@ HRESULT d3d_set_private_data(struct wined3d_private_store *store,
 HRESULT d3d_set_private_data_interface(struct wined3d_private_store *store,
         REFGUID guid, const IUnknown *object) DECLSPEC_HIDDEN;
 
+static inline void *d3d11_calloc(SIZE_T count, SIZE_T size)
+{
+    if (count > ~(SIZE_T)0 / size)
+        return NULL;
+    return HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, count * size);
+}
+
 static inline void read_dword(const char **ptr, DWORD *d)
 {
     memcpy(d, *ptr, sizeof(*d));
diff --git a/dlls/d3d11/inputlayout.c b/dlls/d3d11/inputlayout.c
index d481dd2..69ef985 100644
--- a/dlls/d3d11/inputlayout.c
+++ b/dlls/d3d11/inputlayout.c
@@ -54,8 +54,7 @@ static HRESULT d3d11_input_layout_to_wined3d_declaration(const D3D11_INPUT_ELEME
         return E_FAIL;
     }
 
-    *wined3d_elements = HeapAlloc(GetProcessHeap(), 0, element_count * sizeof(**wined3d_elements));
-    if (!*wined3d_elements)
+    if (!(*wined3d_elements = d3d11_calloc(element_count, sizeof(**wined3d_elements))))
     {
         ERR("Failed to allocate wined3d vertex element array memory.\n");
         HeapFree(GetProcessHeap(), 0, is.elements);
diff --git a/dlls/d3d11/shader.c b/dlls/d3d11/shader.c
index a88c8ce..b1c4f28 100644
--- a/dlls/d3d11/shader.c
+++ b/dlls/d3d11/shader.c
@@ -121,8 +121,7 @@ HRESULT shader_parse_signature(const char *data, DWORD data_size, struct wined3d
         return E_INVALIDARG;
     }
 
-    e = HeapAlloc(GetProcessHeap(), 0, count * sizeof(*e));
-    if (!e)
+    if (!(e = d3d11_calloc(count, sizeof(*e))))
     {
         ERR("Failed to allocate input signature memory.\n");
         return E_OUTOFMEMORY;
-- 
2.1.4




More information about the wine-patches mailing list