Sven Baars : comctl32: Add NULL checks to SetWindowSubclass (Valgrind).
Alexandre Julliard
julliard at winehq.org
Thu Sep 20 13:45:33 CDT 2018
Module: wine
Branch: master
Commit: 04847e68f87b26eeef5cbe6a852b1f3914f956e4
URL: https://source.winehq.org/git/wine.git/?a=commit;h=04847e68f87b26eeef5cbe6a852b1f3914f956e4
Author: Sven Baars <sven.wine at gmail.com>
Date: Wed Sep 19 19:44:18 2018 +0200
comctl32: Add NULL checks to SetWindowSubclass (Valgrind).
Signed-off-by: Sven Baars <sven.wine at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/comctl32/commctrl.c | 3 +++
dlls/comctl32/tests/subclass.c | 31 +++++++++++++++++++++++--------
2 files changed, 26 insertions(+), 8 deletions(-)
diff --git a/dlls/comctl32/commctrl.c b/dlls/comctl32/commctrl.c
index 45b93bd..c228b64 100644
--- a/dlls/comctl32/commctrl.c
+++ b/dlls/comctl32/commctrl.c
@@ -1082,6 +1082,9 @@ BOOL WINAPI SetWindowSubclass (HWND hWnd, SUBCLASSPROC pfnSubclass,
TRACE ("(%p, %p, %lx, %lx)\n", hWnd, pfnSubclass, uIDSubclass, dwRef);
+ if (!hWnd || !pfnSubclass)
+ return FALSE;
+
/* Since the window procedure that we set here has two additional arguments,
* we can't simply set it as the new window procedure of the window. So we
* set our own window procedure and then calculate the other two arguments
diff --git a/dlls/comctl32/tests/subclass.c b/dlls/comctl32/tests/subclass.c
index 75a1343..41ba065 100644
--- a/dlls/comctl32/tests/subclass.c
+++ b/dlls/comctl32/tests/subclass.c
@@ -218,46 +218,61 @@ static LRESULT WINAPI wnd_proc_sub(HWND hwnd, UINT message, WPARAM wParam, LPARA
static void test_subclass(void)
{
+ BOOL ret;
HWND hwnd = CreateWindowExA(0, "TestSubclass", "Test subclass", WS_OVERLAPPEDWINDOW,
100, 100, 200, 200, 0, 0, 0, NULL);
ok(hwnd != NULL, "failed to create test subclass wnd\n");
- pSetWindowSubclass(hwnd, wnd_proc_sub, 2, 0);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 2, 0);
+ ok(ret == TRUE, "Expected TRUE\n");
SendMessageA(hwnd, WM_USER, 1, 0);
SendMessageA(hwnd, WM_USER, 2, 0);
ok_sequence(Sub_BasicTest, "Basic");
- pSetWindowSubclass(hwnd, wnd_proc_sub, 2, DELETE_SELF);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 2, DELETE_SELF);
+ ok(ret == TRUE, "Expected TRUE\n");
SendMessageA(hwnd, WM_USER, 1, 1);
ok_sequence(Sub_DeletedTest, "Deleted");
SendMessageA(hwnd, WM_USER, 1, 0);
ok_sequence(Sub_AfterDeletedTest, "After Deleted");
- pSetWindowSubclass(hwnd, wnd_proc_sub, 2, 0);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 2, 0);
+ ok(ret == TRUE, "Expected TRUE\n");
orig_proc_3 = (WNDPROC)SetWindowLongPtrA(hwnd, GWLP_WNDPROC, (LONG_PTR)wnd_proc_3);
SendMessageA(hwnd, WM_USER, 1, 0);
SendMessageA(hwnd, WM_USER, 2, 0);
ok_sequence(Sub_OldAfterNewTest, "Old after New");
- pSetWindowSubclass(hwnd, wnd_proc_sub, 4, 0);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, 0);
+ ok(ret == TRUE, "Expected TRUE\n");
SendMessageA(hwnd, WM_USER, 1, 0);
ok_sequence(Sub_MixTest, "Mix");
/* Now the fun starts */
- pSetWindowSubclass(hwnd, wnd_proc_sub, 4, SEND_NEST);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, SEND_NEST);
+ ok(ret == TRUE, "Expected TRUE\n");
SendMessageA(hwnd, WM_USER, 1, 1);
ok_sequence(Sub_MixAndNestTest, "Mix and nest");
- pSetWindowSubclass(hwnd, wnd_proc_sub, 4, SEND_NEST | DELETE_SELF);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, SEND_NEST | DELETE_SELF);
+ ok(ret == TRUE, "Expected TRUE\n");
SendMessageA(hwnd, WM_USER, 1, 1);
ok_sequence(Sub_MixNestDelTest, "Mix, nest, del");
- pSetWindowSubclass(hwnd, wnd_proc_sub, 4, 0);
- pSetWindowSubclass(hwnd, wnd_proc_sub, 5, DELETE_PREV);
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 4, 0);
+ ok(ret == TRUE, "Expected TRUE\n");
+ ret = pSetWindowSubclass(hwnd, wnd_proc_sub, 5, DELETE_PREV);
+ ok(ret == TRUE, "Expected TRUE\n");
SendMessageA(hwnd, WM_USER, 1, 1);
ok_sequence(Sub_MixDelPrevTest, "Mix and del prev");
+ ret = pSetWindowSubclass(NULL, wnd_proc_sub, 1, 0);
+ ok(ret == FALSE, "Expected FALSE\n");
+
+ ret = pSetWindowSubclass(hwnd, NULL, 1, 0);
+ ok(ret == FALSE, "Expected FALSE\n");
+
DestroyWindow(hwnd);
}
More information about the wine-cvs
mailing list