[PATCH 1/3] ddraw: DDSD_LPSURFACE requires a non-NULL lpSurface.

Henri Verbeet hverbeet at codeweavers.com
Mon Jan 25 16:18:31 CST 2016


Signed-off-by: Henri Verbeet <hverbeet at codeweavers.com>
---
 dlls/ddraw/surface.c      | 9 ++++++++-
 dlls/ddraw/tests/ddraw1.c | 8 +++++++-
 dlls/ddraw/tests/ddraw2.c | 8 +++++++-
 dlls/ddraw/tests/ddraw4.c | 8 +++++++-
 dlls/ddraw/tests/ddraw7.c | 8 +++++++-
 5 files changed, 36 insertions(+), 5 deletions(-)

diff --git a/dlls/ddraw/surface.c b/dlls/ddraw/surface.c
index 3cf7a56..aaa2ee3 100644
--- a/dlls/ddraw/surface.c
+++ b/dlls/ddraw/surface.c
@@ -5970,7 +5970,7 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
 
     /* If the surface is of the 'ALLOCONLOAD' type, ignore the LPSURFACE
      * field. Frank Herbert's Dune specifies a NULL pointer for lpSurface. */
-    if ((desc->ddsCaps.dwCaps & DDSCAPS_ALLOCONLOAD) || !desc->lpSurface)
+    if (desc->ddsCaps.dwCaps & DDSCAPS_ALLOCONLOAD)
         desc->dwFlags &= ~DDSD_LPSURFACE;
     if (desc->dwFlags & DDSD_LPSURFACE)
     {
@@ -5988,6 +5988,13 @@ HRESULT ddraw_surface_create(struct ddraw *ddraw, const DDSURFACEDESC2 *surface_
             return DDERR_INVALIDPARAMS;
         }
 
+        if (!desc->lpSurface)
+        {
+            WARN("NULL surface memory pointer specified.\n");
+            HeapFree(GetProcessHeap(), 0, texture);
+            return DDERR_INVALIDPARAMS;
+        }
+
         if (format_is_compressed(&desc->u4.ddpfPixelFormat))
         {
             if (version != 4 && (desc->dwFlags & DDSD_PITCH))
diff --git a/dlls/ddraw/tests/ddraw1.c b/dlls/ddraw/tests/ddraw1.c
index 491b696..0dab71e 100644
--- a/dlls/ddraw/tests/ddraw1.c
+++ b/dlls/ddraw/tests/ddraw1.c
@@ -4937,7 +4937,6 @@ static void test_create_surface_pitch(void)
         surface_desc.dwWidth = 63;
         surface_desc.dwHeight = 63;
         U1(surface_desc).lPitch = test_data[i].pitch_in;
-        surface_desc.lpSurface = mem;
         surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
         surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
         U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
@@ -4945,6 +4944,13 @@ static void test_create_surface_pitch(void)
         U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
         U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
         hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        if (test_data[i].flags_in & DDSD_LPSURFACE)
+        {
+            HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
+            ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
+            surface_desc.lpSurface = mem;
+            hr = IDirectDraw_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        }
         ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
                 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
         if (FAILED(hr))
diff --git a/dlls/ddraw/tests/ddraw2.c b/dlls/ddraw/tests/ddraw2.c
index 560b101..2823f40 100644
--- a/dlls/ddraw/tests/ddraw2.c
+++ b/dlls/ddraw/tests/ddraw2.c
@@ -5979,7 +5979,6 @@ static void test_create_surface_pitch(void)
         surface_desc.dwWidth = 63;
         surface_desc.dwHeight = 63;
         U1(surface_desc).lPitch = test_data[i].pitch_in;
-        surface_desc.lpSurface = mem;
         surface_desc.ddpfPixelFormat.dwSize = sizeof(surface_desc.ddpfPixelFormat);
         surface_desc.ddpfPixelFormat.dwFlags = DDPF_RGB;
         U1(surface_desc.ddpfPixelFormat).dwRGBBitCount = 32;
@@ -5987,6 +5986,13 @@ static void test_create_surface_pitch(void)
         U3(surface_desc.ddpfPixelFormat).dwGBitMask = 0x0000ff00;
         U4(surface_desc.ddpfPixelFormat).dwBBitMask = 0x000000ff;
         hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        if (test_data[i].flags_in & DDSD_LPSURFACE)
+        {
+            HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
+            ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
+            surface_desc.lpSurface = mem;
+            hr = IDirectDraw2_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        }
         ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
                 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
         if (FAILED(hr))
diff --git a/dlls/ddraw/tests/ddraw4.c b/dlls/ddraw/tests/ddraw4.c
index 6ccedaf..777c3ff 100644
--- a/dlls/ddraw/tests/ddraw4.c
+++ b/dlls/ddraw/tests/ddraw4.c
@@ -7512,7 +7512,6 @@ static void test_create_surface_pitch(void)
         surface_desc.dwWidth = 63;
         surface_desc.dwHeight = 63;
         U1(surface_desc).lPitch = test_data[i].pitch_in;
-        surface_desc.lpSurface = mem;
         U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
         U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
         U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
@@ -7520,6 +7519,13 @@ static void test_create_surface_pitch(void)
         U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
         U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
         hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        if (test_data[i].flags_in & DDSD_LPSURFACE)
+        {
+            HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
+            ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
+            surface_desc.lpSurface = mem;
+            hr = IDirectDraw4_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        }
         ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
                 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
         if (FAILED(hr))
diff --git a/dlls/ddraw/tests/ddraw7.c b/dlls/ddraw/tests/ddraw7.c
index 268975f..12a3325 100644
--- a/dlls/ddraw/tests/ddraw7.c
+++ b/dlls/ddraw/tests/ddraw7.c
@@ -7361,7 +7361,6 @@ static void test_create_surface_pitch(void)
         surface_desc.dwWidth = 63;
         surface_desc.dwHeight = 63;
         U1(surface_desc).lPitch = test_data[i].pitch_in;
-        surface_desc.lpSurface = mem;
         U4(surface_desc).ddpfPixelFormat.dwSize = sizeof(U4(surface_desc).ddpfPixelFormat);
         U4(surface_desc).ddpfPixelFormat.dwFlags = DDPF_RGB;
         U1(U4(surface_desc).ddpfPixelFormat).dwRGBBitCount = 32;
@@ -7369,6 +7368,13 @@ static void test_create_surface_pitch(void)
         U3(U4(surface_desc).ddpfPixelFormat).dwGBitMask = 0x0000ff00;
         U4(U4(surface_desc).ddpfPixelFormat).dwBBitMask = 0x000000ff;
         hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        if (test_data[i].flags_in & DDSD_LPSURFACE)
+        {
+            HRESULT expected_hr = SUCCEEDED(test_data[i].hr) ? DDERR_INVALIDPARAMS : test_data[i].hr;
+            ok(hr == expected_hr, "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, expected_hr);
+            surface_desc.lpSurface = mem;
+            hr = IDirectDraw7_CreateSurface(ddraw, &surface_desc, &surface, NULL);
+        }
         ok(hr == test_data[i].hr || (test_data[i].placement == DDSCAPS_VIDEOMEMORY && hr == DDERR_NODIRECTDRAWHW),
                 "Test %u: Got unexpected hr %#x, expected %#x.\n", i, hr, test_data[i].hr);
         if (FAILED(hr))
-- 
2.1.4




More information about the wine-patches mailing list