summaryrefslogtreecommitdiff
path: root/sfx2
diff options
context:
space:
mode:
authorXisco Fauli <xiscofauli@libreoffice.org>2023-03-03 16:29:17 +0100
committerAndras Timar <andras.timar@collabora.com>2023-03-12 18:12:19 +0100
commitc98535a304e51c03765fc106c9528ecfb3c13f33 (patch)
tree7268034f711eedec7ced76fa50d05be6960b3ce1 /sfx2
parent22d6c4b6fe673157777a66f6ca603e680bc67794 (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.cxx16
-rw-r--r--sfx2/source/control/dispatch.cxx21
-rw-r--r--sfx2/source/control/unoctitm.cxx4
-rw-r--r--sfx2/source/view/viewfrm.cxx3
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 80dd3e04e56a..d42054d3e33e 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 1268e48643c4..6ac5653db267 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 )