vcl/source/window/mouse.cxx | 19 ++++++++++------ vcl/source/window/toolbox.cxx | 4 +-- vcl/source/window/winproc.cxx | 47 +++++++++++++++++++++++++----------------- 3 files changed, 43 insertions(+), 27 deletions(-)
New commits: commit 71888075c160d97855f35b306bd6eb01a2922d1f Author: Gabriel Masei <gabriel.ma...@1and1.ro> AuthorDate: Fri May 28 14:37:52 2021 +0300 Commit: Gabriel Masei <gabriel.ma...@1and1.ro> CommitDate: Thu Jun 3 11:06:37 2021 +0200 vcl: check mpWindowImpl before referencing it Fixed some cases generating crashes because mpWindowImpl was not checked for nullptr. Change-Id: I5540f9f21a870b02655b5bf2afdbf3a8153c1519 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/116330 Tested-by: Jenkins Reviewed-by: Jan Holesovsky <ke...@collabora.com> diff --git a/vcl/source/window/mouse.cxx b/vcl/source/window/mouse.cxx index d1b3590ed97b..b2f978dbe7cf 100644 --- a/vcl/source/window/mouse.cxx +++ b/vcl/source/window/mouse.cxx @@ -251,7 +251,7 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags ) bool bAsyncFocusWaiting = false; vcl::Window *pFrame = pSVData->maFrameData.mpFirstFrame; - while( pFrame ) + while( pFrame && pFrame->mpWindowImpl && pFrame->mpWindowImpl->mpFrameData ) { if( pFrame != mpWindowImpl->mpFrameWindow.get() && pFrame->mpWindowImpl->mpFrameData->mnFocusId ) { @@ -274,6 +274,8 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags ) bMustNotGrabFocus = true; break; } + if (!pParent->mpWindowImpl) + break; pParent = pParent->mpWindowImpl->mpParent; } @@ -331,13 +333,16 @@ void Window::ImplGrabFocus( GetFocusFlags nFlags ) else { vcl::Window* pNewOverlapWindow = ImplGetFirstOverlapWindow(); - vcl::Window* pNewRealWindow = pNewOverlapWindow->ImplGetWindow(); - pNewOverlapWindow->mpWindowImpl->mbActive = true; - pNewOverlapWindow->Activate(); - if ( pNewRealWindow != pNewOverlapWindow ) + if ( pNewOverlapWindow && pNewOverlapWindow->mpWindowImpl ) { - pNewRealWindow->mpWindowImpl->mbActive = true; - pNewRealWindow->Activate(); + vcl::Window* pNewRealWindow = pNewOverlapWindow->ImplGetWindow(); + pNewOverlapWindow->mpWindowImpl->mbActive = true; + pNewOverlapWindow->Activate(); + if ( pNewRealWindow != pNewOverlapWindow && pNewRealWindow && pNewRealWindow->mpWindowImpl ) + { + pNewRealWindow->mpWindowImpl->mbActive = true; + pNewRealWindow->Activate(); + } } } diff --git a/vcl/source/window/toolbox.cxx b/vcl/source/window/toolbox.cxx index a993b697b100..38704c2dae69 100644 --- a/vcl/source/window/toolbox.cxx +++ b/vcl/source/window/toolbox.cxx @@ -3057,7 +3057,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt ) vcl::Window *pWin = pFocusWin->GetParent(); while (pWin) { - if(pWin->ImplGetWindowImpl()->mbToolBox) + if(pWin->ImplGetWindowImpl() && pWin->ImplGetWindowImpl()->mbToolBox) { bFocusWindowIsAToolBoxChild = true; break; @@ -3066,7 +3066,7 @@ void ToolBox::MouseMove( const MouseEvent& rMEvt ) } } - if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) ) + if( bFocusWindowIsAToolBoxChild || (pFocusWin && pFocusWin->ImplGetWindowImpl() && pFocusWin->ImplGetWindowImpl()->mbToolBox && pFocusWin != this) ) bDrawHotSpot = false; if ( mbDragging ) diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx index dfb7a89e6aa0..80e306b17625 100644 --- a/vcl/source/window/winproc.cxx +++ b/vcl/source/window/winproc.cxx @@ -805,17 +805,20 @@ static vcl::Window* ImplGetKeyInputWindow( vcl::Window* pWindow ) vcl::Window* pChild = pSVData->mpWinData->mpFirstFloat; while (pChild) { - if (pChild->ImplGetWindowImpl()->mbFloatWin) + if (pChild->ImplGetWindowImpl()) { - if (static_cast<FloatingWindow *>(pChild)->GrabsFocus()) - break; - } - else if (pChild->ImplGetWindowImpl()->mbDockWin) - { - vcl::Window* pParent = pChild->GetWindow(GetWindowType::RealParent); - if (pParent && pParent->ImplGetWindowImpl()->mbFloatWin && - static_cast<FloatingWindow *>(pParent)->GrabsFocus()) - break; + if (pChild->ImplGetWindowImpl()->mbFloatWin) + { + if (static_cast<FloatingWindow *>(pChild)->GrabsFocus()) + break; + } + else if (pChild->ImplGetWindowImpl()->mbDockWin) + { + vcl::Window* pParent = pChild->GetWindow(GetWindowType::RealParent); + if (pParent && pParent->ImplGetWindowImpl()->mbFloatWin && + static_cast<FloatingWindow *>(pParent)->GrabsFocus()) + break; + } } pChild = pChild->GetParent(); } @@ -823,7 +826,7 @@ static vcl::Window* ImplGetKeyInputWindow( vcl::Window* pWindow ) if (!pChild) pChild = pWindow; - pChild = pChild->ImplGetWindowImpl()->mpFrameData->mpFocusWin; + pChild = pChild->ImplGetWindowImpl() && pChild->ImplGetWindowImpl()->mpFrameData ? pChild->ImplGetWindowImpl()->mpFrameData->mpFocusWin.get() : nullptr; // no child - then no input if ( !pChild ) @@ -1756,6 +1759,9 @@ static void ImplActivateFloatingWindows( vcl::Window const * pWindow, bool bActi IMPL_LINK_NOARG(vcl::Window, ImplAsyncFocusHdl, void*, void) { + if (!ImplGetWindowImpl() || !ImplGetWindowImpl()->mpFrameData) + return; + ImplGetWindowImpl()->mpFrameData->mnFocusId = nullptr; // If the status has been preserved, because we got back the focus @@ -1814,22 +1820,27 @@ IMPL_LINK_NOARG(vcl::Window, ImplAsyncFocusHdl, void*, void) { // transfer the FocusWindow vcl::Window* pOverlapWindow = pFocusWin->ImplGetFirstOverlapWindow(); - pOverlapWindow->ImplGetWindowImpl()->mpLastFocusWindow = pFocusWin; + if ( pOverlapWindow && pOverlapWindow->ImplGetWindowImpl() ) + pOverlapWindow->ImplGetWindowImpl()->mpLastFocusWindow = pFocusWin; pSVData->mpWinData->mpFocusWin = nullptr; - if ( pFocusWin->ImplGetWindowImpl()->mpCursor ) + if ( pFocusWin->ImplGetWindowImpl() && pFocusWin->ImplGetWindowImpl()->mpCursor ) pFocusWin->ImplGetWindowImpl()->mpCursor->ImplHide(); // call the Deactivate vcl::Window* pOldOverlapWindow = pFocusWin->ImplGetFirstOverlapWindow(); vcl::Window* pOldRealWindow = pOldOverlapWindow->ImplGetWindow(); - pOldOverlapWindow->ImplGetWindowImpl()->mbActive = false; - pOldOverlapWindow->Deactivate(); - if ( pOldRealWindow != pOldOverlapWindow ) + if (pOldOverlapWindow && pOldOverlapWindow->ImplGetWindowImpl() && + pOldRealWindow && pOldRealWindow->ImplGetWindowImpl()) { - pOldRealWindow->ImplGetWindowImpl()->mbActive = false; - pOldRealWindow->Deactivate(); + pOldOverlapWindow->ImplGetWindowImpl()->mbActive = false; + pOldOverlapWindow->Deactivate(); + if ( pOldRealWindow != pOldOverlapWindow ) + { + pOldRealWindow->ImplGetWindowImpl()->mbActive = false; + pOldRealWindow->Deactivate(); + } } // TrackingMode is ended in ImplHandleLoseFocus _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits