From 0bd130f213a2c5a4c06c30785703316d1d73ea4a Mon Sep 17 00:00:00 2001 From: Zhiyi Zhang Date: Tue, 31 Mar 2020 21:39:19 +0800 Subject: [PATCH] d3d8/tests: Fix possible test failures. expect_messages points to a local variable. When it goes out of scope, it reads into random memory, causing failures. Signed-off-by: Zhiyi Zhang Signed-off-by: Henri Verbeet Signed-off-by: Alexandre Julliard --- dlls/d3d8/tests/device.c | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/dlls/d3d8/tests/device.c b/dlls/d3d8/tests/device.c index d87832b716d..b7aa02adabb 100644 --- a/dlls/d3d8/tests/device.c +++ b/dlls/d3d8/tests/device.c @@ -2662,6 +2662,7 @@ static void test_wndproc(void) { struct wndproc_thread_param thread_params; struct device_desc device_desc; + static WINDOWPOS windowpos; IDirect3DDevice8 *device; WNDCLASSA wc = {0}; IDirect3D8 *d3d8; @@ -2677,7 +2678,6 @@ static void test_wndproc(void) DEVMODEW devmode; LONG change_ret, device_style; BOOL ret; - WINDOWPOS windowpos; static const struct message create_messages[] = { @@ -2777,7 +2777,7 @@ static void test_wndproc(void) {WM_SIZE, FOCUS_WINDOW, TRUE, SIZE_MAXIMIZED}, {0, 0, FALSE, 0}, }; - struct message mode_change_messages[] = + static const struct message mode_change_messages[] = { {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0}, {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0}, @@ -2790,7 +2790,7 @@ static void test_wndproc(void) * ShowWindow does not send such a message because the window is already visible. */ {0, 0, FALSE, 0}, }; - struct message mode_change_messages_hidden[] = + static const struct message mode_change_messages_hidden[] = { {WM_WINDOWPOSCHANGING, DEVICE_WINDOW, FALSE, 0}, {WM_WINDOWPOSCHANGED, DEVICE_WINDOW, FALSE, 0}, @@ -2857,6 +2857,9 @@ static void test_wndproc(void) return; } + filter_messages = NULL; + expect_messages = NULL; + wc.lpfnWndProc = test_proc; wc.lpszClassName = "d3d8_test_wndproc_wc"; ok(RegisterClassA(&wc), "Failed to register window class.\n"); @@ -3200,6 +3203,7 @@ static void test_wndproc(void) flush_events(); ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it, i=%u.\n", expect_messages->message, expect_messages->window, i); + expect_messages = NULL; /* World of Warplanes hides the window by removing WS_VISIBLE and expects Reset() to show it again. */ device_style = GetWindowLongA(device_window, GWL_STYLE); @@ -3219,6 +3223,7 @@ static void test_wndproc(void) flush_events(); ok(!expect_messages->message, "Expected message %#x for window %#x, but didn't receive it.\n", expect_messages->message, expect_messages->window); + expect_messages = NULL; ok(windowpos.hwnd == device_window && !windowpos.hwndInsertAfter && !windowpos.x && !windowpos.y && !windowpos.cx && !windowpos.cy @@ -3242,6 +3247,7 @@ static void test_wndproc(void) done: filter_messages = NULL; + expect_messages = NULL; IDirect3D8_Release(d3d8); SetEvent(thread_params.test_finished); @@ -3272,6 +3278,9 @@ static void test_wndproc_windowed(void) d3d8 = Direct3DCreate8(D3D_SDK_VERSION); ok(!!d3d8, "Failed to create a D3D object.\n"); + filter_messages = NULL; + expect_messages = NULL; + wc.lpfnWndProc = test_proc; wc.lpszClassName = "d3d8_test_wndproc_wc"; ok(RegisterClassA(&wc), "Failed to register window class.\n"); @@ -4177,6 +4186,9 @@ static void test_device_window_reset(void) HRESULT hr; ULONG ref; + filter_messages = NULL; + expect_messages = NULL; + wc.lpfnWndProc = test_proc; wc.lpszClassName = "d3d8_test_wndproc_wc"; ok(RegisterClassA(&wc), "Failed to register window class.\n");