[PATCH] d3dx9_36: Fixed memset of a -2 32bit value (Coverity)

Marcus Meissner marcus at jet.franken.de
Sat Aug 6 06:13:28 CDT 2011


Hi,

You can't memset entities larger than bytes.

(Also this code passes negative values via DWORDs, which are unsigned, which
probably is also incorrect. But I am leaving that as-is.)

-1 is semi-safe, but only due to the nature of the negative representation. Fix it too.

CID 5259 et.al.

CC: michael at mcdonnell.dk

Ciao, Marcus
---
 dlls/d3dx9_36/tests/mesh.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)

diff --git a/dlls/d3dx9_36/tests/mesh.c b/dlls/d3dx9_36/tests/mesh.c
index 39c78e6..a68e9c5 100644
--- a/dlls/d3dx9_36/tests/mesh.c
+++ b/dlls/d3dx9_36/tests/mesh.c
@@ -5384,7 +5384,7 @@ static void test_convert_adjacency_to_point_reps(void)
         }
 
         /* Convert adjacency to point representation */
-        memset(point_reps, -1, tc[i].num_vertices * sizeof(*point_reps));
+        for (j = 0; j < tc[i].num_vertices; j++) point_reps[j] = -1;
         hr = mesh->lpVtbl->ConvertAdjacencyToPointReps(mesh, tc[i].adjacency, point_reps);
         ok(hr == D3D_OK, "ConvertAdjacencyToPointReps failed case %d. "
            "Got %x expected D3D_OK\n", i, hr);
@@ -5921,7 +5921,8 @@ static void test_convert_point_reps_to_adjacency(void)
         }
 
         /* Convert point representation to adjacency*/
-        memset(adjacency, -2, VERTS_PER_FACE * tc[i].num_faces * sizeof(*adjacency));
+        for (j = 0; j < VERTS_PER_FACE * tc[i].num_faces; j++) adjacency[j] = -2;
+
         hr = mesh->lpVtbl->ConvertPointRepsToAdjacency(mesh, tc[i].point_reps, adjacency);
         ok(hr == D3D_OK, "ConvertPointRepsToAdjacency failed case %d. "
            "Got %x expected D3D_OK\n", i, hr);
@@ -5935,7 +5936,7 @@ static void test_convert_point_reps_to_adjacency(void)
         }
 
         /* NULL point representation is considered identity. */
-        memset(adjacency, -2, VERTS_PER_FACE * tc[i].num_faces * sizeof(*adjacency));
+        for (j = 0; j < VERTS_PER_FACE * tc[i].num_faces; j++) adjacency[j] = -2;
         hr = mesh_null_check->lpVtbl->ConvertPointRepsToAdjacency(mesh, NULL, adjacency);
         ok(hr == D3D_OK, "ConvertPointRepsToAdjacency NULL point_reps. "
                      "Got %x expected D3D_OK\n", hr);
-- 
1.7.3.4




More information about the wine-patches mailing list