From 6c9e1a4735f5b025b3432fc9150356f97fccc63b Mon Sep 17 00:00:00 2001 From: Henri Verbeet Date: Mon, 25 Jan 2016 23:18:31 +0100 Subject: [PATCH] ddraw: DDSD_LPSURFACE requires a non-NULL lpSurface. Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- 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 3cf7a5626a6..aaa2ee31535 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 491b69636fb..0dab71e22d6 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 560b101f136..2823f40add8 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 6ccedaf074c..777c3ffcb4f 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 268975f75eb..12a33255a86 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))