Jacek Caban : user32: Fix nameA pointer in alloc_menu_nameW.

Alexandre Julliard julliard at winehq.org
Mon Mar 14 17:47:37 CDT 2022


Module: wine
Branch: master
Commit: fa77147b5b105cb22196b6ca6977c1de9ec77d14
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=fa77147b5b105cb22196b6ca6977c1de9ec77d14

Author: Jacek Caban <jacek at codeweavers.com>
Date:   Mon Mar 14 11:43:07 2022 +0100

user32: Fix nameA pointer in alloc_menu_nameW.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=52651
Signed-off-by: Jacek Caban <jacek at codeweavers.com>
Signed-off-by: Huw Davies <huw at codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 dlls/user32/class.c       |  1 +
 dlls/user32/tests/class.c | 48 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 49 insertions(+)

diff --git a/dlls/user32/class.c b/dlls/user32/class.c
index 3b6b70b8004..5d1c44a441d 100644
--- a/dlls/user32/class.c
+++ b/dlls/user32/class.c
@@ -174,6 +174,7 @@ static BOOL alloc_menu_nameW( struct client_menu_name *ret, const WCHAR *menu_na
         DWORD lenA = WideCharToMultiByte( CP_ACP, 0, menu_name, lenW, NULL, 0, NULL, NULL );
         ret->nameW = HeapAlloc( GetProcessHeap(), 0, lenA + lenW * sizeof(WCHAR) );
         if (!ret->nameW) return FALSE;
+        ret->nameA = (char *)(ret->nameW + lenW);
         memcpy( ret->nameW, menu_name, lenW * sizeof(WCHAR) );
         WideCharToMultiByte( CP_ACP, 0, menu_name, lenW, ret->nameA, lenA, NULL, NULL );
     }
diff --git a/dlls/user32/tests/class.c b/dlls/user32/tests/class.c
index 590e342585d..64fc3c014e3 100644
--- a/dlls/user32/tests/class.c
+++ b/dlls/user32/tests/class.c
@@ -1545,6 +1545,53 @@ static void test_uxtheme(void)
     UnregisterClassA(class_name, GetModuleHandleA(NULL));
 }
 
+static void test_class_name(void)
+{
+    WCHAR class_name[] = L"ClassNameTest";
+    HINSTANCE hinst = GetModuleHandleW(0);
+    WNDCLASSEXW wcex;
+    const WCHAR *nameW;
+    const char *nameA;
+    UINT_PTR res;
+    HWND hwnd;
+
+    memset(&wcex, 0, sizeof wcex);
+    wcex.cbSize        = sizeof wcex;
+    wcex.lpfnWndProc   = ClassTest_WndProc;
+    wcex.hIcon         = LoadIconW(0, (LPCWSTR)IDI_APPLICATION);
+    wcex.hInstance     = hinst;
+    wcex.lpszClassName = class_name;
+    wcex.lpszMenuName  = L"menu name";
+    ok(RegisterClassExW(&wcex), "RegisterClassExW returned 0\n");
+    hwnd = CreateWindowExW(0, class_name, NULL, WS_OVERLAPPEDWINDOW,
+                           0, 0, 0, 0, NULL, NULL, hinst, 0);
+    ok(hwnd != NULL, "Window was not created\n");
+
+    nameA = (const char *)GetClassLongPtrA(hwnd, GCLP_MENUNAME);
+    ok(!strcmp(nameA, "menu name"), "unexpected class name %s\n", debugstr_a(nameA));
+    nameW = (const WCHAR *)GetClassLongPtrW(hwnd, GCLP_MENUNAME);
+    ok(!wcscmp(nameW, L"menu name"), "unexpected class name %s\n", debugstr_w(nameW));
+
+    res = SetClassLongPtrA(hwnd, GCLP_MENUNAME, (LONG_PTR)"nameA");
+    todo_wine
+    ok(res, "SetClassLongPtrA returned 0\n");
+    nameA = (const char *)GetClassLongPtrA(hwnd, GCLP_MENUNAME);
+    ok(!strcmp(nameA, "nameA"), "unexpected class name %s\n", debugstr_a(nameA));
+    nameW = (const WCHAR *)GetClassLongPtrW(hwnd, GCLP_MENUNAME);
+    ok(!wcscmp(nameW, L"nameA"), "unexpected class name %s\n", debugstr_w(nameW));
+
+    res = SetClassLongPtrW(hwnd, GCLP_MENUNAME, (LONG_PTR)L"nameW");
+    todo_wine
+    ok(res, "SetClassLongPtrW returned 0\n");
+    nameA = (const char *)GetClassLongPtrA(hwnd, GCLP_MENUNAME);
+    ok(!strcmp(nameA, "nameW"), "unexpected class name %s\n", debugstr_a(nameA));
+    nameW = (const WCHAR *)GetClassLongPtrW(hwnd, GCLP_MENUNAME);
+    ok(!wcscmp(nameW, L"nameW"), "unexpected class name %s\n", debugstr_w(nameW));
+
+    DestroyWindow(hwnd);
+    UnregisterClassW(class_name, hinst);
+}
+
 START_TEST(class)
 {
     char **argv;
@@ -1578,6 +1625,7 @@ START_TEST(class)
     test_icons();
     test_comctl32_classes();
     test_actctx_classes();
+    test_class_name();
 
     /* this test unregisters the Button class so it should be executed at the end */
     test_instances();




More information about the wine-cvs mailing list