From 66d77112ed9a2acd097a490c4509850884c049bc Mon Sep 17 00:00:00 2001 From: Yuhang Zhao <2546789017@qq.com> Date: Sun, 8 May 2022 21:50:08 +0800 Subject: [PATCH] win32: fix possible crash in some very rare cases Signed-off-by: Yuhang Zhao <2546789017@qq.com> --- src/core/framelesshelper_win.cpp | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/core/framelesshelper_win.cpp b/src/core/framelesshelper_win.cpp index 6ca8dd9..fad57f8 100644 --- a/src/core/framelesshelper_win.cpp +++ b/src/core/framelesshelper_win.cpp @@ -58,7 +58,6 @@ struct Win32Helper Q_GLOBAL_STATIC(Win32Helper, g_win32Helper) FRAMELESSHELPER_BYTEARRAY_CONSTANT2(Win32MessageTypeName, "windows_generic_MSG") -static const QString qThemeSettingChangeEventName = QString::fromWCharArray(kThemeSettingChangeEventName); FRAMELESSHELPER_STRING_CONSTANT(MonitorFromWindow) FRAMELESSHELPER_STRING_CONSTANT(GetMonitorInfoW) FRAMELESSHELPER_STRING_CONSTANT(ScreenToClient) @@ -1035,8 +1034,9 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me }(); if (isWin10OrGreater && data.dragBarWindowId) { switch (uMsg) { - case WM_SIZE: - case WM_DISPLAYCHANGE: { + case WM_SIZE: // Sent to a window after its size has changed. + case WM_DISPLAYCHANGE: // Sent to a window when the display resolution has changed. + { if (!resizeDragBarWindow(windowId, data.dragBarWindowId)) { qWarning() << "Failed to re-position the drag bar window."; } @@ -1052,8 +1052,8 @@ bool FramelessHelperWin::nativeEventFilter(const QByteArray &eventType, void *me }(); if (isWin10RS1OrGreater) { if (uMsg == WM_SETTINGCHANGE) { - if ((wParam == 0) && (QString::fromWCharArray(reinterpret_cast(lParam)) - .compare(qThemeSettingChangeEventName, Qt::CaseInsensitive) == 0)) { + if ((wParam == 0) && (lParam != 0) // lParam sometimes may be NULL. + && (std::wcscmp(reinterpret_cast(lParam), kThemeSettingChangeEventName) == 0)) { systemThemeChanged = true; const bool dark = Utils::shouldAppsUseDarkMode(); Utils::updateWindowFrameBorderColor(windowId, dark);