Henri Verbeet : d2d1: Introduce a helper function to allocate arrays.

Alexandre Julliard julliard at winehq.org
Wed Jan 31 15:23:28 CST 2018


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

Author: Henri Verbeet <hverbeet at codeweavers.com>
Date:   Wed Jan 31 19:07:40 2018 +0330

d2d1: Introduce a helper function to allocate arrays.

Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/d2d1/bitmap.c        | 6 ++++--
 dlls/d2d1/brush.c         | 4 ++--
 dlls/d2d1/d2d1_private.h  | 9 +++++++++
 dlls/d2d1/geometry.c      | 6 +++---
 dlls/d2d1/render_target.c | 4 ++--
 dlls/d2d1/stroke.c        | 2 +-
 6 files changed, 21 insertions(+), 10 deletions(-)

diff --git a/dlls/d2d1/bitmap.c b/dlls/d2d1/bitmap.c
index 43ed094..028fab3 100644
--- a/dlls/d2d1/bitmap.c
+++ b/dlls/d2d1/bitmap.c
@@ -509,9 +509,11 @@ HRESULT d2d_bitmap_create_from_wic_bitmap(ID2D1Factory *factory, ID3D10Device *d
     }
 
     pitch = ((bpp * size.width) + 15) & ~15;
-    data_size = pitch * size.height;
-    if (!(data = heap_alloc(data_size)))
+    if (pitch / bpp < size.width)
         return E_OUTOFMEMORY;
+    if (!(data = d2d_calloc(size.height, pitch)))
+        return E_OUTOFMEMORY;
+    data_size = size.height * pitch;
 
     rect.X = 0;
     rect.Y = 0;
diff --git a/dlls/d2d1/brush.c b/dlls/d2d1/brush.c
index 6759019..0531a3a 100644
--- a/dlls/d2d1/brush.c
+++ b/dlls/d2d1/brush.c
@@ -142,7 +142,7 @@ HRESULT d2d_gradient_create(ID2D1Factory *factory, ID3D10Device *device, const D
     unsigned int i;
     HRESULT hr;
 
-    if (!(data = heap_alloc_zero(2 * stop_count * sizeof(*data))))
+    if (!(data = d2d_calloc(stop_count, 2 * sizeof(*data))))
     {
         ERR("Failed to allocate data.\n");
         return E_OUTOFMEMORY;
@@ -205,7 +205,7 @@ HRESULT d2d_gradient_create(ID2D1Factory *factory, ID3D10Device *device, const D
     (*gradient)->view = view;
 
     (*gradient)->stop_count = stop_count;
-    if (!((*gradient)->stops = heap_alloc(stop_count * sizeof(*stops))))
+    if (!((*gradient)->stops = d2d_calloc(stop_count, sizeof(*stops))))
     {
         ID3D10ShaderResourceView_Release(view);
         heap_free(*gradient);
diff --git a/dlls/d2d1/d2d1_private.h b/dlls/d2d1/d2d1_private.h
index caeb4b9..2c10252 100644
--- a/dlls/d2d1/d2d1_private.h
+++ b/dlls/d2d1/d2d1_private.h
@@ -477,6 +477,15 @@ void d2d_transformed_geometry_init(struct d2d_geometry *geometry, ID2D1Factory *
         ID2D1Geometry *src_geometry, const D2D_MATRIX_3X2_F *transform) DECLSPEC_HIDDEN;
 struct d2d_geometry *unsafe_impl_from_ID2D1Geometry(ID2D1Geometry *iface) DECLSPEC_HIDDEN;
 
+static inline void *d2d_calloc(size_t count, size_t size)
+{
+    SIZE_T s = count * size;
+
+    if (size && s / size != count)
+        return NULL;
+    return heap_alloc(s);
+}
+
 static inline void d2d_matrix_multiply(D2D_MATRIX_3X2_F *a, const D2D_MATRIX_3X2_F *b)
 {
     D2D_MATRIX_3X2_F tmp = *a;
diff --git a/dlls/d2d1/geometry.c b/dlls/d2d1/geometry.c
index 88beee2..c805084 100644
--- a/dlls/d2d1/geometry.c
+++ b/dlls/d2d1/geometry.c
@@ -2052,7 +2052,7 @@ static HRESULT d2d_path_geometry_triangulate(struct d2d_geometry *geometry)
         return S_OK;
     }
 
-    if (!(vertices = heap_alloc(vertex_count * sizeof(*vertices))))
+    if (!(vertices = d2d_calloc(vertex_count, sizeof(*vertices))))
         return E_OUTOFMEMORY;
 
     for (i = 0, j = 0; i < geometry->u.path.figure_count; ++i)
@@ -2819,8 +2819,8 @@ static HRESULT d2d_geometry_resolve_beziers(struct d2d_geometry *geometry)
         geometry->fill.bezier_vertex_count += 3 * geometry->u.path.figures[i].bezier_control_count;
     }
 
-    if (!(geometry->fill.bezier_vertices = heap_alloc(geometry->fill.bezier_vertex_count
-            * sizeof(*geometry->fill.bezier_vertices))))
+    if (!(geometry->fill.bezier_vertices = d2d_calloc(geometry->fill.bezier_vertex_count,
+            sizeof(*geometry->fill.bezier_vertices))))
     {
         ERR("Failed to allocate bezier vertices array.\n");
         geometry->fill.bezier_vertex_count = 0;
diff --git a/dlls/d2d1/render_target.c b/dlls/d2d1/render_target.c
index 73f15f7..cc820cf 100644
--- a/dlls/d2d1/render_target.c
+++ b/dlls/d2d1/render_target.c
@@ -1175,12 +1175,12 @@ static void d2d_rt_draw_glyph_run_bitmap(struct d2d_d3d_render_target *render_ta
 
     if (texture_type == DWRITE_TEXTURE_CLEARTYPE_3x1)
         bitmap_size.width *= 3;
-    opacity_values_size = bitmap_size.width * bitmap_size.height;
-    if (!(opacity_values = heap_alloc(opacity_values_size)))
+    if (!(opacity_values = d2d_calloc(bitmap_size.height, bitmap_size.width)))
     {
         ERR("Failed to allocate opacity values.\n");
         goto done;
     }
+    opacity_values_size = bitmap_size.height * bitmap_size.width;
 
     if (FAILED(hr = IDWriteGlyphRunAnalysis_CreateAlphaTexture(analysis,
             texture_type, &bounds, opacity_values, opacity_values_size)))
diff --git a/dlls/d2d1/stroke.c b/dlls/d2d1/stroke.c
index a0830e3..63f88c7 100644
--- a/dlls/d2d1/stroke.c
+++ b/dlls/d2d1/stroke.c
@@ -212,7 +212,7 @@ HRESULT d2d_stroke_style_init(struct d2d_stroke_style *style, ID2D1Factory *fact
         if (!dashes || !dash_count)
             return E_INVALIDARG;
 
-        if (!(style->dashes = heap_alloc(dash_count * sizeof(*style->dashes))))
+        if (!(style->dashes = d2d_calloc(dash_count, sizeof(*style->dashes))))
             return E_OUTOFMEMORY;
         memcpy(style->dashes, dashes, dash_count * sizeof(*style->dashes));
         style->dash_count = dash_count;




More information about the wine-cvs mailing list