sc/source/ui/view/tabvwshb.cxx   |    6 ++++++
 sfx2/source/control/ctrlitem.cxx |   16 +++++++++-------
 sfx2/source/control/dispatch.cxx |   21 +++++++++++++++------
 sfx2/source/control/unoctitm.cxx |    4 +---
 sfx2/source/view/viewfrm.cxx     |    3 +++
 5 files changed, 34 insertions(+), 16 deletions(-)

New commits:
commit 9eb083ab732512c3ab64007c3be1c54be97172f6
Author:     Xisco Fauli <[email protected]>
AuthorDate: Fri Mar 3 16:29:17 2023 +0100
Commit:     Caolán McNamara <[email protected]>
CommitDate: Sat Mar 4 20:49:41 2023 +0000

    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 <[email protected]>
    Reviewed-by: Caolán McNamara <[email protected]>

diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx
index 11fba3153460..04c97bcea64f 100644
--- a/sc/source/ui/view/tabvwshb.cxx
+++ b/sc/source/ui/view/tabvwshb.cxx
@@ -712,6 +712,9 @@ bool ScTabViewShell::IsSignatureLineSigned()
 void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
 {
     SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
+    if (!pSh)
+        return;
+
     ScUndoManager* pUndoManager = 
static_cast<ScUndoManager*>(pSh->GetUndoManager());
 
     const SfxItemSet* pReqArgs = rReq.GetArgs();
@@ -812,6 +815,9 @@ void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
 void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
 {
     SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
+    if (!pSh)
+        return;
+
     SfxUndoManager* pUndoManager = pSh->GetUndoManager();
     ScUndoManager* pScUndoManager = dynamic_cast<ScUndoManager*>(pUndoManager);
 
diff --git a/sfx2/source/control/ctrlitem.cxx b/sfx2/source/control/ctrlitem.cxx
index 1e5dc277909b..21618056469a 100644
--- a/sfx2/source/control/ctrlitem.cxx
+++ b/sfx2/source/control/ctrlitem.cxx
@@ -323,15 +323,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 e72f4706dd8e..8cd0ec2c2fb3 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 50b238d7a5d3..c340db4005fe 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -846,9 +846,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 246c20707b8d..8d4cb75f531b 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -955,6 +955,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 )

Reply via email to