[PATCH] comctl32/edit: Initialize font metrics to nonzero in WM_NCCREATE.
Roman Pišl
rpisl at seznam.cz
Thu Mar 26 14:48:44 CDT 2020
v2: Introduced helper function.
v3: Improved helper function (I really didn't like the previous).
v4: Simpler and less intrusive solution (tested on all affected apps from bugzilla).
Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=48803
Signed-off-by: Roman Pišl <rpisl at seznam.cz>
---
dlls/comctl32/edit.c | 7 +++++
dlls/comctl32/tests/edit.c | 59 ++++++++++++++++++++++++++++++++++++++
2 files changed, 66 insertions(+)
diff --git a/dlls/comctl32/edit.c b/dlls/comctl32/edit.c
index d02d7af7b9..3a1a5b791d 100644
--- a/dlls/comctl32/edit.c
+++ b/dlls/comctl32/edit.c
@@ -4488,6 +4488,13 @@ static LRESULT EDIT_WM_NCCreate(HWND hwnd, LPCREATESTRUCTW lpcs)
else if (es->style & WS_BORDER)
SetWindowLongW(hwnd, GWL_STYLE, es->style & ~WS_BORDER);
+ /*
+ * Initialize to avoid division by zero,
+ * a proper value is set during WM_Create.
+ */
+ es->line_height = 1;
+ es->char_width = 1;
+
return TRUE;
cleanup:
diff --git a/dlls/comctl32/tests/edit.c b/dlls/comctl32/tests/edit.c
index cec6025077..3bfbee4ddd 100644
--- a/dlls/comctl32/tests/edit.c
+++ b/dlls/comctl32/tests/edit.c
@@ -1768,6 +1768,64 @@ static BOOL is_font_installed(const char*name)
return ret;
}
+static WNDPROC orig_class_proc;
+
+static LRESULT CALLBACK test_class_proc(HWND hwnd, UINT message, WPARAM wParam, LPARAM lParam)
+{
+ RECT rect;
+ LRESULT result;
+
+ switch (message)
+ {
+ case WM_NCCREATE:
+ result = CallWindowProcA(orig_class_proc, hwnd, message, wParam, lParam);
+
+ memset(&rect, 0, sizeof(rect));
+ SendMessageA(hwnd, EM_GETRECT, 0, (LPARAM)&rect);
+ ok(!rect.right && !rect.bottom, "Invalid size after NCCREATE: %d x %d\n", rect.right, rect.bottom);
+
+ /* test that early messages don't crash or cause unexpected behavior */
+ SendMessageA(hwnd, EM_SETSEL, 0, 0);
+ SendMessageA(hwnd, WM_SIZE, 0, 0);
+
+ return result;
+
+ case WM_CREATE:
+ /* test that early messages don't crash or cause unexpected behavior */
+ SendMessageA(hwnd, EM_SETSEL, 0, 0);
+ SendMessageA(hwnd, WM_SIZE, 0, 0);
+
+ break;
+ }
+
+ return CallWindowProcA(orig_class_proc, hwnd, message, wParam, lParam);
+}
+
+static void test_early_messages(void)
+{
+ BOOL ret;
+ ATOM atom;
+ HWND hwEdit;
+ WNDCLASSA cls;
+
+ ret = GetClassInfoA(NULL, "Edit", &cls);
+ ok(ret, "Failed to get class info.\n");
+
+ orig_class_proc = cls.lpfnWndProc;
+ cls.lpfnWndProc = test_class_proc;
+ cls.lpszClassName = "TestClassName";
+
+ atom = RegisterClassA(&cls);
+ ok(atom != 0, "Failed to register class.\n");
+
+ hwEdit = CreateWindowExA(0, (LPCSTR)MAKEINTATOM(atom), "Text Text", ES_MULTILINE | WS_BORDER | ES_AUTOHSCROLL | ES_AUTOVSCROLL,
+ 10, 10, 300, 300, NULL, NULL, hinst, NULL);
+ ok(hwEdit != NULL, "Failed to create a window.\n");
+
+ DestroyWindow(hwEdit);
+ UnregisterClassA((LPCSTR)MAKEINTATOM(atom), hinst);
+}
+
static void test_margins(void)
{
DWORD old_margins, new_margins;
@@ -3393,6 +3451,7 @@ START_TEST(edit)
test_edit_control_6();
test_edit_control_limittext();
test_edit_control_scroll();
+ test_early_messages();
test_margins();
test_margins_font_change();
test_text_position();
--
2.20.1
More information about the wine-devel
mailing list