sw/inc/viewsh.hxx                    |    2 +-
 sw/source/core/crsr/crsrsh.cxx       |   22 +++++++++++++---------
 sw/source/core/crsr/viscrs.cxx       |   10 ++++------
 sw/source/core/frmedt/feflyole.cxx   |    6 +++++-
 sw/source/core/view/viewsh.cxx       |   16 +++++++++++-----
 sw/source/uibase/docvw/edtwin.cxx    |    3 ++-
 sw/source/uibase/uiview/viewsrch.cxx |   20 +++++++++++++-------
 sw/source/uibase/wrtsh/wrtsh3.cxx    |    3 ++-
 8 files changed, 51 insertions(+), 31 deletions(-)

New commits:
commit ba39f47385302c6cbbbb2a72fa5218dd1f82514d
Author:     Xisco Fauli <xiscofa...@libreoffice.org>
AuthorDate: Tue Jul 1 17:26:56 2025 +0200
Commit:     Xisco Fauli <xiscofa...@libreoffice.org>
CommitDate: Thu Jul 3 16:47:38 2025 +0200

    sw: use SAL_RET_MAYBENULL in GetSfxViewShell()
    
    after
    commit 7ac9630d2258ae4b40917b79b38fa6cab0842078
    Author: Caolán McNamara <caolan.mcnam...@collabora.com>
    Date:   Tue Jul 1 09:24:54 2025 +0100
    
        null GetSfxViewShell() deref
    
    Change-Id: If7e5019cf49917d163b36fc1aab24de64e10c4ea
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187242
    Reviewed-by: Xisco Fauli <xiscofa...@libreoffice.org>
    Tested-by: Jenkins
    (cherry picked from commit 7768dd07b87c4e94365aceba1a8342d894dbc3d3)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/187336

diff --git a/sw/inc/viewsh.hxx b/sw/inc/viewsh.hxx
index dc2b09f4440a..9ce783c693f3 100644
--- a/sw/inc/viewsh.hxx
+++ b/sw/inc/viewsh.hxx
@@ -497,7 +497,7 @@ public:
     SW_DLLPUBLIC static void SetCareDialog(const 
std::shared_ptr<weld::Window>& rNew);
     static weld::Window*  GetCareDialog(SwViewShell const & rVSh);
 
-    SfxViewShell   *GetSfxViewShell() const { return mpSfxViewShell; }
+    SAL_RET_MAYBENULL SfxViewShell   *GetSfxViewShell() const { return 
mpSfxViewShell; }
     void           SetSfxViewShell(SfxViewShell *pNew) { mpSfxViewShell = 
pNew; }
 
     // Selection of  Draw Engine has been changed.
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 67795975289a..9068f6ac5aed 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -2545,8 +2545,12 @@ void SwCursorShell::UpdateCursor( sal_uInt16 eFlags, 
bool bIdleEnd, ScrollSizeMo
 
 void SwCursorShell::sendLOKCursorUpdates()
 {
-    SwView* pView = static_cast<SwView*>(GetSfxViewShell());
-    if (!pView || !pView->GetWrtShellPtr())
+    SfxViewShell* pNotifySh = GetSfxViewShell();
+    if (!pNotifySh)
+        return;
+
+    SwView* pView = static_cast<SwView*>(pNotifySh);
+    if (!pView->GetWrtShellPtr())
         return;
 
     SwWrtShell* pShell = &pView->GetWrtShell();
@@ -2612,7 +2616,7 @@ void SwCursorShell::sendLOKCursorUpdates()
     }
 
     OString pChar = aJsonWriter.finishAndGetAsOString();
-    GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_TABLE_SELECTED, 
pChar);
+    pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_TABLE_SELECTED, pChar);
 }
 
 void SwCursorShell::RefreshBlockCursor()
@@ -2900,11 +2904,11 @@ void SwCursorShell::ShowCursor()
     m_pCurrentCursor->SetShowTextInputFieldOverlay( true );
     m_pCurrentCursor->SetShowContentControlOverlay(true);
 
-    if (comphelper::LibreOfficeKit::isActive())
+    if (SfxViewShell* pNotifySh = comphelper::LibreOfficeKit::isActive() ? 
GetSfxViewShell() : nullptr)
     {
         const OString aPayload = OString::boolean(m_bSVCursorVis);
-        
GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, 
aPayload);
-        SfxLokHelper::notifyOtherViews(GetSfxViewShell(), 
LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
+        pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, 
aPayload);
+        SfxLokHelper::notifyOtherViews(pNotifySh, 
LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
     }
 
     UpdateCursor();
@@ -2922,11 +2926,11 @@ void SwCursorShell::HideCursor()
     m_pCurrentCursor->SetShowContentControlOverlay(false);
     m_pVisibleCursor->Hide();
 
-    if (comphelper::LibreOfficeKit::isActive())
+    if (SfxViewShell* pNotifySh = comphelper::LibreOfficeKit::isActive() ? 
GetSfxViewShell() : nullptr)
     {
         OString aPayload = OString::boolean(m_bSVCursorVis);
-        
GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, 
aPayload);
-        SfxLokHelper::notifyOtherViews(GetSfxViewShell(), 
LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
+        pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_CURSOR_VISIBLE, 
aPayload);
+        SfxLokHelper::notifyOtherViews(pNotifySh, 
LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
     }
 }
 
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index 39a5020542e4..05c8c5be9cb9 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -335,11 +335,9 @@ std::optional<OString> SwVisibleCursor::getLOKPayload(int 
nType, int nViewId) co
         else if (bIsSelection)
         {
             SwWrtShell* pShell = 
m_pCursorShell->GetDoc()->GetDocShell()->GetWrtShell();
-
-            if (pShell)
+            if (SfxViewShell* pNotifySh = pShell ? 
m_pCursorShell->GetSfxViewShell() : nullptr)
             {
-                SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT>
-                     aSet(m_pCursorShell->GetSfxViewShell()->GetPool());
+                SfxItemSetFixed<RES_TXTATR_INETFMT, RES_TXTATR_INETFMT> 
aSet(pNotifySh->GetPool());
                 pShell->GetCurAttr(aSet);
                 const SwFormatINetFormat* pItem = nullptr;
                 if(SfxItemState::SET <= aSet.GetItemState( RES_TXTATR_INETFMT, 
true, &pItem ))
@@ -829,12 +827,12 @@ void SwSelPaintRects::HighlightContentControl()
     }
     else
     {
-        if (comphelper::LibreOfficeKit::isActive() && m_pContentControlOverlay)
+        if (SfxViewShell* pNotifySh = comphelper::LibreOfficeKit::isActive() 
&& m_pContentControlOverlay ? GetShell()->GetSfxViewShell() : nullptr)
         {
             tools::JsonWriter aJson;
             aJson.put("action", "hide");
             OString pJson(aJson.finishAndGetAsOString());
-            
GetShell()->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL,
 pJson);
+            
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL, pJson);
         }
         m_pContentControlOverlay.reset();
 
diff --git a/sw/source/core/frmedt/feflyole.cxx 
b/sw/source/core/frmedt/feflyole.cxx
index fd4348ed36e0..e65d61f03272 100644
--- a/sw/source/core/frmedt/feflyole.cxx
+++ b/sw/source/core/frmedt/feflyole.cxx
@@ -88,7 +88,11 @@ UIName SwFEShell::GetUniqueFrameName() const
 
 bool SwFEShell::FinishOLEObj()                      // Server is terminated
 {
-    SfxInPlaceClient* pIPClient = GetSfxViewShell()->GetIPClient();
+    SfxViewShell* pNotifySh = GetSfxViewShell();
+    if (!pNotifySh)
+        return false;
+
+    SfxInPlaceClient* pIPClient = pNotifySh->GetIPClient();
     if ( !pIPClient )
         return false;
 
diff --git a/sw/source/core/view/viewsh.cxx b/sw/source/core/view/viewsh.cxx
index fdfaab4620c6..d92a31c84708 100644
--- a/sw/source/core/view/viewsh.cxx
+++ b/sw/source/core/view/viewsh.cxx
@@ -2213,11 +2213,14 @@ void SwViewShell::PaintTile(VirtualDevice &rDevice, int 
contextWidth, int contex
 
         // Changing the zoom value doesn't always trigger the updating of
         // the client ole object area, so we call it directly.
-        SfxInPlaceClient* pIPClient = GetSfxViewShell()->GetIPClient();
-        if (pIPClient)
+        if (SfxViewShell* pNotifySh = GetSfxViewShell())
         {
-            pIPClient->VisAreaChanged();
+            if (SfxInPlaceClient* pIPClient = pNotifySh->GetIPClient())
+            {
+                pIPClient->VisAreaChanged();
+            }
         }
+
         // Make sure the map mode (disabled in 
SwXTextDocument::initializeForTiledRendering()) is still disabled.
         GetWin()->EnableMapMode(false);
     }
@@ -2559,8 +2562,11 @@ void SwViewShell::ImplApplyViewOptions( const 
SwViewOption &rOpt )
         InvalidateLayout( true );
     }
 
-    SwXTextDocument* pModel = 
comphelper::getFromUnoTunnel<SwXTextDocument>(GetSfxViewShell()->GetCurrentDocument());
-    SfxLokHelper::notifyViewRenderState(GetSfxViewShell(), pModel);
+    if (SfxViewShell* pNotifySh = GetSfxViewShell())
+    {
+        SwXTextDocument* pModel = 
comphelper::getFromUnoTunnel<SwXTextDocument>(pNotifySh->GetCurrentDocument());
+        SfxLokHelper::notifyViewRenderState(pNotifySh, pModel);
+    }
 
     pMyWin->Invalidate();
     if ( bReformat )
diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index 9ec64d2e636a..8ae5d8a38e41 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -5729,7 +5729,8 @@ void SwEditWin::LoseFocus()
 bool SwEditWin::IsViewReadonly() const
 {
     SwWrtShell &rSh = m_rView.GetWrtShell();
-    return (m_rView.GetDocShell()->IsReadOnly() && rSh.IsCursorReadonly()) || 
(rSh.GetSfxViewShell() && rSh.GetSfxViewShell()->IsLokReadOnlyView());
+    SfxViewShell* pNotifySh = rSh.GetSfxViewShell();
+    return (m_rView.GetDocShell()->IsReadOnly() && rSh.IsCursorReadonly()) || 
(pNotifySh && pNotifySh->IsLokReadOnlyView());
 }
 
 void SwEditWin::Command( const CommandEvent& rCEvt )
diff --git a/sw/source/uibase/uiview/viewsrch.cxx 
b/sw/source/uibase/uiview/viewsrch.cxx
index 90656c3d3b38..1d70837aa7ce 100644
--- a/sw/source/uibase/uiview/viewsrch.cxx
+++ b/sw/source/uibase/uiview/viewsrch.cxx
@@ -118,12 +118,14 @@ static void lcl_emitSearchResultCallbacks(SvxSearchItem 
const * pSearchItem, SwW
     boost::property_tree::write_json(aStream, aTree);
     OString aPayload( aStream.str() );
 
-    
pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION,
 aPayload);
+    SfxViewShell* pNotifySh = pWrtShell->GetSfxViewShell();
+    if (pNotifySh)
+        
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_RESULT_SELECTION, 
aPayload);
 
     if(bHighlightAll)
     {   // FindAll disables this during find, do it once when done.
-        
SfxLokHelper::notifyUpdate(pWrtShell->GetSfxViewShell(),LOK_CALLBACK_TEXT_SELECTION);
-        
SfxLokHelper::notifyOtherViewsUpdatePerViewId(pWrtShell->GetSfxViewShell(), 
LOK_CALLBACK_TEXT_VIEW_SELECTION);
+        SfxLokHelper::notifyUpdate(pNotifySh,LOK_CALLBACK_TEXT_SELECTION);
+        SfxLokHelper::notifyOtherViewsUpdatePerViewId(pNotifySh, 
LOK_CALLBACK_TEXT_VIEW_SELECTION);
     }
 }
 
@@ -278,7 +280,8 @@ void SwView::ExecSearch(SfxRequest& rReq)
 #if HAVE_FEATURE_DESKTOP
                     if( !bQuiet )
                     {
-                        
m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND,
 s_pSrchItem->GetSearchString().toUtf8());
+                        if (SfxViewShell* pNotifySh = 
m_pWrtShell->GetSfxViewShell())
+                            
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, 
s_pSrchItem->GetSearchString().toUtf8());
                         
SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
                     }
 #endif
@@ -387,7 +390,8 @@ void SwView::ExecSearch(SfxRequest& rReq)
 #if HAVE_FEATURE_DESKTOP
                         if( !bQuiet )
                         {
-                            
m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND,
 s_pSrchItem->GetSearchString().toUtf8());
+                            if (SfxViewShell* pNotifySh = 
m_pWrtShell->GetSfxViewShell())
+                                
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, 
s_pSrchItem->GetSearchString().toUtf8());
                             
SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
                         }
 #endif
@@ -556,7 +560,8 @@ bool SwView::SearchAndWrap(bool bApi)
         if( !bApi )
         {
 #if HAVE_FEATURE_DESKTOP
-            
m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND,
 s_pSrchItem->GetSearchString().toUtf8());
+            if (SfxViewShell* pNotifySh = m_pWrtShell->GetSfxViewShell())
+                
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, 
s_pSrchItem->GetSearchString().toUtf8());
             SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
 #endif
         }
@@ -611,7 +616,8 @@ bool SwView::SearchAndWrap(bool bApi)
     }
     else if(!bApi)
     {
-        
m_pWrtShell->GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND,
 s_pSrchItem->GetSearchString().toUtf8());
+        if (SfxViewShell* pNotifySh = m_pWrtShell->GetSfxViewShell())
+            
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_SEARCH_NOT_FOUND, 
s_pSrchItem->GetSearchString().toUtf8());
         SvxSearchDialogWrapper::SetSearchLabel(SearchLabel::NotFound);
     }
 #endif
diff --git a/sw/source/uibase/wrtsh/wrtsh3.cxx 
b/sw/source/uibase/wrtsh/wrtsh3.cxx
index bafb1bd19957..67ba8e22b6e7 100644
--- a/sw/source/uibase/wrtsh/wrtsh3.cxx
+++ b/sw/source/uibase/wrtsh/wrtsh3.cxx
@@ -109,7 +109,8 @@ bool SwWrtShell::GotoContentControl(const 
SwFormatContentControl& rContentContro
                 tools::JsonWriter aJson;
                 aJson.put("action", "change-picture");
                 OString pJson(aJson.finishAndGetAsOString());
-                
GetSfxViewShell()->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL,
+                if (SfxViewShell* pNotifySh = GetSfxViewShell())
+                    
pNotifySh->libreOfficeKitViewCallback(LOK_CALLBACK_CONTENT_CONTROL,
                                                               pJson);
             }
             else

Reply via email to