sfx2/source/control/bindings.cxx |    3 +++
 sfx2/source/control/dispatch.cxx |   16 +++++++++-------
 sfx2/source/view/viewfrm.cxx     |    4 ++--
 3 files changed, 14 insertions(+), 9 deletions(-)

New commits:
commit 23c9e1acf88f772024e930dd2cf3a9e10435a8c3
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Wed May 22 10:17:20 2024 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Tue Jun 4 12:19:02 2024 +0200

    sfx2: warning C6011: Dereferencing NULL pointer
    
    Change-Id: Ie65284c3ded0c5789f0be5bbd770d190a92fecec
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167922
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins
    Signed-off-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167981
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    (cherry picked from commit 63870676cda0f36c3763869dfb0fed49da0a2104)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/167937
    Reviewed-by: Hossein <hoss...@libreoffice.org>
    Reviewed-by: Christian Lohmaier <lohmaier+libreoff...@googlemail.com>
    Reviewed-by: Ilmari Lauhakangas <ilmari.lauhakan...@libreoffice.org>

diff --git a/sfx2/source/control/bindings.cxx b/sfx2/source/control/bindings.cxx
index 47ddda28136f..8beca9364e71 100644
--- a/sfx2/source/control/bindings.cxx
+++ b/sfx2/source/control/bindings.cxx
@@ -945,6 +945,9 @@ SfxPoolItemHolder SfxBindings::Execute_Impl( sal_uInt16 
nId, const SfxPoolItem**
         if ( dynamic_cast< const SfxModule *>( pShell ) == nullptr && 
dynamic_cast< const SfxApplication *>( pShell ) == nullptr && dynamic_cast< 
const SfxViewFrame *>( pShell ) == nullptr )
             return SfxPoolItemHolder();
 
+    if (!pShell)
+        return SfxPoolItemHolder();
+
     SfxItemPool &rPool = pShell->GetPool();
     SfxRequest aReq( nId, nCallMode, rPool );
     aReq.SetModifier( nModi );
diff --git a/sfx2/source/control/dispatch.cxx b/sfx2/source/control/dispatch.cxx
index fe7271677fbf..bedad9a6241a 100644
--- a/sfx2/source/control/dispatch.cxx
+++ b/sfx2/source/control/dispatch.cxx
@@ -707,7 +707,7 @@ bool SfxDispatcher::GetShellAndSlot_Impl(sal_uInt16 nSlot, 
SfxShell** ppShell,
 
         *ppShell = GetShell(aSvr.GetShellLevel());
         *ppSlot = aSvr.GetSlot();
-        if ( nullptr == (*ppSlot)->GetExecFnc() && bRealSlot )
+        if ( nullptr == (*ppSlot)->GetExecFnc() && bRealSlot && *ppShell )
             *ppSlot = (*ppShell)->GetInterface()->GetRealSlot(*ppSlot);
         // Check only real slots as enum slots don't have an execute function!
         return !bRealSlot || ((nullptr != *ppSlot) && (nullptr != 
(*ppSlot)->GetExecFnc()) );
@@ -986,13 +986,15 @@ void 
SfxDispatcher::PostMsgHandler(std::unique_ptr<SfxRequest> pReq)
         SfxSlotServer aSvr;
         if ( FindServer_(pReq->GetSlot(), aSvr ) ) // HACK(x), whatever that 
was supposed to mean
         {
-            const SfxSlot *pSlot = aSvr.GetSlot();
-            SfxShell *pSh = GetShell(aSvr.GetShellLevel());
+            if (SfxShell *pSh = GetShell(aSvr.GetShellLevel()))
+            {
+                const SfxSlot *pSlot = aSvr.GetSlot();
 
-            // When the pSlot is a "Pseudoslot" for macros or Verbs, it can
-            // be destroyed in the Call_Impl, thus do not use it anymore!
-            pReq->SetSynchronCall( false );
-            Call_Impl( *pSh, *pSlot, *pReq, pReq->AllowsRecording() ); //! why 
bRecord?
+                // When the pSlot is a "Pseudoslot" for macros or Verbs, it can
+                // be destroyed in the Call_Impl, thus do not use it anymore!
+                pReq->SetSynchronCall( false );
+                Call_Impl( *pSh, *pSlot, *pReq, pReq->AllowsRecording() ); //! 
why bRecord?
+            }
         }
     }
     else
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index b14ff206fa96..202064f13081 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1093,8 +1093,8 @@ void SfxViewFrame::PopShellAndSubShells_Impl( 
SfxViewShell& i_rViewShell )
         if ( nLevel )
         {
             // more sub shells on the stack, which were not affected by 
PopSubShells_Impl
-            SfxShell *pSubShell = m_pDispatcher->GetShell( nLevel-1 );
-            m_pDispatcher->Pop( *pSubShell, SfxDispatcherPopFlags::POP_UNTIL | 
SfxDispatcherPopFlags::POP_DELETE );
+            if (SfxShell *pSubShell = m_pDispatcher->GetShell( nLevel-1 ))
+                m_pDispatcher->Pop( *pSubShell, 
SfxDispatcherPopFlags::POP_UNTIL | SfxDispatcherPopFlags::POP_DELETE );
         }
         m_pDispatcher->Pop( i_rViewShell );
         m_pDispatcher->Flush();

Reply via email to