diff options
author | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-03-03 16:29:17 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2023-03-07 16:48:44 +0000 |
commit | bd323bb9554265ec093fed3274cb232fbf0cd2ec (patch) | |
tree | 1b949c25ed8b63de52f6c5f22cf2775a88367b6a /sfx2 | |
parent | ebc60f5ccab910d6974b5c386b2c0243f9eb030b (diff) |
check GetShell
it might return nullptr
Change-Id: I65b43d69f4757b6c331582ca2e256cdea01377af
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148194
Tested-by: Jenkins
Tested-by: Caolán McNamara <caolanm@redhat.com>
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
(cherry picked from commit 9eb083ab732512c3ab64007c3be1c54be97172f6)
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/148231
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/source/control/ctrlitem.cxx | 16 | ||||
-rw-r--r-- | sfx2/source/control/dispatch.cxx | 21 | ||||
-rw-r--r-- | sfx2/source/control/unoctitm.cxx | 4 | ||||
-rw-r--r-- | sfx2/source/view/viewfrm.cxx | 3 |
4 files changed, 28 insertions, 16 deletions
diff --git a/sfx2/source/control/ctrlitem.cxx b/sfx2/source/control/ctrlitem.cxx index 28edfec666de..df7ba128659d 100644 --- a/sfx2/source/control/ctrlitem.cxx +++ b/sfx2/source/control/ctrlitem.cxx @@ -325,15 +325,17 @@ MapUnit SfxControllerItem::GetCoreMetric() const const SfxSlotServer *pServer = pCache->GetSlotServer( *pDispat ); if ( pServer ) { - SfxShell *pSh = pDispat->GetShell( pServer->GetShellLevel() ); - SfxItemPool &rPool = pSh->GetPool(); - sal_uInt16 nWhich = rPool.GetWhich( nId ); + if (SfxShell *pSh = pDispat->GetShell( pServer->GetShellLevel() )) + { + SfxItemPool &rPool = pSh->GetPool(); + sal_uInt16 nWhich = rPool.GetWhich( nId ); - // invalidate slot and its message|slot server as 'global' information - // about the validated message|slot server is not made available - pCache->Invalidate( true ); + // invalidate slot and its message|slot server as 'global' information + // about the validated message|slot server is not made available + pCache->Invalidate( true ); - return rPool.GetMetric( nWhich ); + return rPool.GetMetric( nWhich ); + } } } diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx index 17edf97cc16d..9d85075de433 100644 --- a/sfx2/source/control/dispatch.cxx +++ b/sfx2/source/control/dispatch.cxx @@ -774,11 +774,13 @@ const SfxSlot* SfxDispatcher::GetSlot( const OUString& rCommand ) for ( sal_uInt16 i = 0; i < nTotCount; ++i ) { - SfxShell *pObjShell = GetShell(i); - SfxInterface *pIFace = pObjShell->GetInterface(); - const SfxSlot *pSlot = pIFace->GetSlot( rCommand ); - if ( pSlot ) - return pSlot; + if (SfxShell *pObjShell = GetShell(i)) + { + SfxInterface *pIFace = pObjShell->GetInterface(); + const SfxSlot *pSlot = pIFace->GetSlot( rCommand ); + if ( pSlot ) + return pSlot; + } } return nullptr; @@ -1152,6 +1154,9 @@ void SfxDispatcher::Update_Impl_( bool bUIActive, bool bIsMDIApp, bool bIsIPOwne for ( sal_uInt16 nShell = nTotCount; nShell > 0; --nShell ) { SfxShell *pShell = GetShell( nShell-1 ); + if (!pShell) + continue; + SfxInterface *pIFace = pShell->GetInterface(); // don't consider shells if "Hidden" or "Quiet" @@ -1567,6 +1572,9 @@ bool SfxDispatcher::FindServer_(sal_uInt16 nSlot, SfxSlotServer& rServer) for ( sal_uInt16 i = nFirstShell; i < nTotCount; ++i ) { SfxShell *pObjShell = GetShell(i); + if (!pObjShell) + continue; + SfxInterface *pIFace = pObjShell->GetInterface(); const SfxSlot *pSlot = pIFace->GetSlot(nSlot); @@ -1646,7 +1654,8 @@ bool SfxDispatcher::FillState_(const SfxSlotServer& rSvr, SfxItemSet& rState, // Determine the object and call the Message of this object SfxShell *pSh = GetShell(rSvr.GetShellLevel()); - DBG_ASSERT(pSh, "ObjectShell not found"); + if (!pSh) + return false; SfxStateFunc pFunc; diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx index 6f68292f46b4..45588bf1ccb9 100644 --- a/sfx2/source/control/unoctitm.cxx +++ b/sfx2/source/control/unoctitm.cxx @@ -860,9 +860,7 @@ void SfxDispatchController_Impl::StateChanged( sal_uInt16 nSID, SfxItemState eSt // TODO/LATER: what about the FormShell? Does it use any metric data?! Perhaps it should use the Pool of the document! if ( pSlotServ && pDispatcher ) { - SfxShell* pShell = pDispatcher->GetShell( pSlotServ->GetShellLevel() ); - DBG_ASSERT( pShell, "Can't get core metric without shell!" ); - if ( pShell ) + if (SfxShell* pShell = pDispatcher->GetShell( pSlotServ->GetShellLevel() )) eMapUnit = GetCoreMetric( pShell->GetPool(), nSID ); } diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx index 68ea4a3f8933..f20d4932494a 100644 --- a/sfx2/source/view/viewfrm.cxx +++ b/sfx2/source/view/viewfrm.cxx @@ -954,6 +954,9 @@ void SfxViewFrame::ExecHistory_Impl( SfxRequest &rReq ) { // Is there an Undo-Manager on the top Shell? SfxShell *pSh = GetDispatcher()->GetShell(0); + if (!pSh) + return; + SfxUndoManager* pShUndoMgr = pSh->GetUndoManager(); bool bOK = false; if ( pShUndoMgr ) |