include/sfx2/lokhelper.hxx          |    2 +-
 sc/source/ui/view/gridwin.cxx       |    8 ++++----
 sc/source/ui/view/gridwin4.cxx      |    2 +-
 sd/source/ui/view/ViewShellBase.cxx |    2 +-
 sfx2/source/view/lokhelper.cxx      |    7 +++----
 sfx2/source/view/viewsh.cxx         |    2 +-
 svx/source/svdraw/svdmrkv.cxx       |    2 +-
 sw/source/core/crsr/crsrsh.cxx      |    4 ++--
 sw/source/core/crsr/viscrs.cxx      |    2 +-
 9 files changed, 15 insertions(+), 16 deletions(-)

New commits:
commit fb77b106ac2223e7b051e561645d65389fad1807
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Jul 23 19:46:29 2025 +0100
Commit:     Miklos Vajna <vmik...@collabora.com>
CommitDate: Tue Jul 29 14:09:05 2025 +0200

    notifyOtherView derefs its ViewShell
    
    because lcl_generateJSON does
    
    Change-Id: I1c7e361a44d693db8ae100f76904f3e6f915c209
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/188296
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Miklos Vajna <vmik...@collabora.com>

diff --git a/include/sfx2/lokhelper.hxx b/include/sfx2/lokhelper.hxx
index 00f4468dcaab..38160cb85db2 100644
--- a/include/sfx2/lokhelper.hxx
+++ b/include/sfx2/lokhelper.hxx
@@ -165,7 +165,7 @@ public:
     static void notifyOtherViews(const SfxViewShell* pThisView, int nType,
                                  const boost::property_tree::ptree& rTree);
     /// Same as notifyOtherViews(), but works on a selected "other" view, not 
on all of them.
-    static void notifyOtherView(const SfxViewShell* pThisView, SfxViewShell 
const* pOtherView,
+    static void notifyOtherView(const SfxViewShell& rThisView, SfxViewShell 
const* pOtherView,
                                 int nType, std::string_view rKey, const 
OString& rPayload);
     /// Same as notifyOtherViews(), the property-tree version, but works on a 
selected "other" view, not on all of them.
     static void notifyOtherView(const SfxViewShell& rThisView, SfxViewShell 
const* pOtherView,
diff --git a/sc/source/ui/view/gridwin.cxx b/sc/source/ui/view/gridwin.cxx
index b275a6f5b5be..c7633c9c4569 100644
--- a/sc/source/ui/view/gridwin.cxx
+++ b/sc/source/ui/view/gridwin.cxx
@@ -6203,7 +6203,7 @@ void ScGridWindow::notifyKitCellViewCursor(const 
SfxViewShell* pForShell) const
             aCursor = pForTabView->GetViewData().describeCellCursorAt(
                 mrViewData.GetCurX(), mrViewData.GetCurY()); // our position.
     }
-    SfxLokHelper::notifyOtherView(pViewShell, pForShell, 
LOK_CALLBACK_CELL_VIEW_CURSOR, "rectangle", aCursor);
+    SfxLokHelper::notifyOtherView(*pViewShell, pForShell, 
LOK_CALLBACK_CELL_VIEW_CURSOR, "rectangle", aCursor);
 }
 
 // Send our cursor details to a view described by @pForShell, or all views
@@ -6225,7 +6225,7 @@ void ScGridWindow::updateKitCellCursor(const 
SfxViewShell* pForShell) const
 
         if (pForShell)
         {
-            SfxLokHelper::notifyOtherView(pViewShell, pForShell,
+            SfxLokHelper::notifyOtherView(*pViewShell, pForShell,
                     LOK_CALLBACK_CELL_VIEW_CURSOR, "rectangle", aCursor);
         }
         else
@@ -6497,7 +6497,7 @@ void ScGridWindow::UpdateKitSelection(const 
std::vector<tools::Rectangle>& rRect
         std::vector<tools::Rectangle> aPixelRects;
         pGrid->GetPixelRectsFor(mrViewData.GetMarkData() /* ours */, 
aPixelRects);
         auto aOtherLogicRects = convertPixelToLogical(pOther->GetViewData(), 
aPixelRects, aDummyBBox);
-        SfxLokHelper::notifyOtherView(pViewShell, pOther, 
LOK_CALLBACK_TEXT_VIEW_SELECTION,
+        SfxLokHelper::notifyOtherView(*pViewShell, pOther, 
LOK_CALLBACK_TEXT_VIEW_SELECTION,
                                       "selection", 
rectanglesToString(aOtherLogicRects));
     }
 }
@@ -6544,7 +6544,7 @@ void ScGridWindow::updateOtherKitSelections() const
             
pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_TEXT_SELECTION, 
aRectsString);
         }
         else
-            SfxLokHelper::notifyOtherView(it, pViewShell, 
LOK_CALLBACK_TEXT_VIEW_SELECTION,
+            SfxLokHelper::notifyOtherView(*it, pViewShell, 
LOK_CALLBACK_TEXT_VIEW_SELECTION,
                                           "selection", aRectsString);
     }
 }
diff --git a/sc/source/ui/view/gridwin4.cxx b/sc/source/ui/view/gridwin4.cxx
index c9e4b8a8d72f..14365b0af5b0 100644
--- a/sc/source/ui/view/gridwin4.cxx
+++ b/sc/source/ui/view/gridwin4.cxx
@@ -353,7 +353,7 @@ void ScGridWindow::InvalidateLOKViewCursor(const 
tools::Rectangle& rCursorRect,
                 Fraction aZoomY = rOtherViewData.GetZoomY();
                 if (aZoomX == aScaleX && aZoomY == aScaleY)
                 {
-                    SfxLokHelper::notifyOtherView(pThisViewShell, 
pOtherViewShell,
+                    SfxLokHelper::notifyOtherView(*pThisViewShell, 
pOtherViewShell,
                             LOK_CALLBACK_INVALIDATE_VIEW_CURSOR, "rectangle", 
rCursorRect.toString());
                 }
             }
diff --git a/sd/source/ui/view/ViewShellBase.cxx 
b/sd/source/ui/view/ViewShellBase.cxx
index bfbff51d1389..74f0ca0bf6ec 100644
--- a/sd/source/ui/view/ViewShellBase.cxx
+++ b/sd/source/ui/view/ViewShellBase.cxx
@@ -1138,7 +1138,7 @@ void ViewShellBase::NotifyCursor(SfxViewShell* 
pOtherShell) const
             if (pWin && pWin->GetMapMode().GetMapUnit() == MapUnit::Map100thMM)
                 aRectangle = o3tl::toTwips(aRectangle, o3tl::Length::mm100);
             OString sRectangle = aRectangle.toString();
-            SfxLokHelper::notifyOtherView(&pDrawViewShell->GetViewShellBase(), 
pOtherShell, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRectangle);
+            SfxLokHelper::notifyOtherView(pDrawViewShell->GetViewShellBase(), 
pOtherShell, LOK_CALLBACK_VIEW_LOCK, "rectangle", sRectangle);
         }
     }
     else
diff --git a/sfx2/source/view/lokhelper.cxx b/sfx2/source/view/lokhelper.cxx
index 06fa32600fb8..a0c2beb5c57e 100644
--- a/sfx2/source/view/lokhelper.cxx
+++ b/sfx2/source/view/lokhelper.cxx
@@ -548,15 +548,14 @@ static inline OString lcl_generateJSON(const 
SfxViewShell& rView, std::string_vi
     return lcl_generateJSON(rView, SfxLokHelper::getView(rView), rKey, 
rPayload);
 }
 
-void SfxLokHelper::notifyOtherView(const SfxViewShell* pThisView, SfxViewShell 
const* pOtherView,
+void SfxLokHelper::notifyOtherView(const SfxViewShell& rThisView, SfxViewShell 
const* pOtherView,
                                    int nType, std::string_view rKey, const 
OString& rPayload)
 {
-    assert(pThisView != nullptr && "pThisView must be valid");
     if (DisableCallbacks::disabled())
         return;
 
-    const OString aPayload = lcl_generateJSON(*pThisView, rKey, rPayload);
-    const int viewId = SfxLokHelper::getView(pThisView);
+    const OString aPayload = lcl_generateJSON(rThisView, rKey, rPayload);
+    const int viewId = SfxLokHelper::getView(rThisView);
     pOtherView->libreOfficeKitViewCallbackWithViewId(nType, aPayload, viewId);
 }
 
diff --git a/sfx2/source/view/viewsh.cxx b/sfx2/source/view/viewsh.cxx
index 621919c3bb4d..2fa20798113e 100644
--- a/sfx2/source/view/viewsh.cxx
+++ b/sfx2/source/view/viewsh.cxx
@@ -3571,7 +3571,7 @@ void SfxViewShell::NotifyOtherView(OutlinerViewShell* 
pOther, int nType, const O
     if (!pOtherShell)
         return;
 
-    SfxLokHelper::notifyOtherView(this, pOtherShell, nType, rKey, rPayload);
+    SfxLokHelper::notifyOtherView(*this, pOtherShell, nType, rKey, rPayload);
 }
 
 void SfxViewShell::dumpAsXml(xmlTextWriterPtr pWriter) const
diff --git a/svx/source/svdraw/svdmrkv.cxx b/svx/source/svdraw/svdmrkv.cxx
index 40a29c179302..192fdc028409 100644
--- a/svx/source/svdraw/svdmrkv.cxx
+++ b/svx/source/svdraw/svdmrkv.cxx
@@ -1315,7 +1315,7 @@ void SdrMarkView::SetMarkHandlesForLOKit(tools::Rectangle 
const & rRect, const S
             // Another shell wants to know about our existing
             // selection.
             if (pViewShell != pOtherShell)
-                SfxLokHelper::notifyOtherView(pViewShell, pOtherShell, 
LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", sSelectionTextView);
+                SfxLokHelper::notifyOtherView(*pViewShell, pOtherShell, 
LOK_CALLBACK_GRAPHIC_VIEW_SELECTION, "selection", sSelectionTextView);
         }
         else if (pViewShell)
         {
diff --git a/sw/source/core/crsr/crsrsh.cxx b/sw/source/core/crsr/crsrsh.cxx
index 3990ff5317cf..958ad2c26211 100644
--- a/sw/source/core/crsr/crsrsh.cxx
+++ b/sw/source/core/crsr/crsrsh.cxx
@@ -1687,7 +1687,7 @@ void SwCursorShell::NotifyCursor(SfxViewShell* 
pOtherShell) const
         if (OutlinerView* pOutlinerView = pView->GetTextEditOutlinerView())
         {
             OString sRect = pOutlinerView->GetOutputArea().toString();
-            SfxLokHelper::notifyOtherView(GetSfxViewShell(), pOtherShell, 
LOK_CALLBACK_VIEW_LOCK, "rectangle", sRect);
+            SfxLokHelper::notifyOtherView(*GetSfxViewShell(), pOtherShell, 
LOK_CALLBACK_VIEW_LOCK, "rectangle", sRect);
         }
     }
     else
@@ -1698,7 +1698,7 @@ void SwCursorShell::NotifyCursor(SfxViewShell* 
pOtherShell) const
         if (GetSfxViewShell() != pOtherShell)
         {
             OString aPayload = OString::boolean(m_bSVCursorVis);
-            SfxLokHelper::notifyOtherView(GetSfxViewShell(), pOtherShell, 
LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
+            SfxLokHelper::notifyOtherView(*GetSfxViewShell(), pOtherShell, 
LOK_CALLBACK_VIEW_CURSOR_VISIBLE, "visible", aPayload);
         }
         // Text selection.
         m_pCurrentCursor->Show(pOtherShell);
diff --git a/sw/source/core/crsr/viscrs.cxx b/sw/source/core/crsr/viscrs.cxx
index ad1fbdc16de2..d46ffc2aa218 100644
--- a/sw/source/core/crsr/viscrs.cxx
+++ b/sw/source/core/crsr/viscrs.cxx
@@ -970,7 +970,7 @@ void SwShellCursor::Show(SfxViewShell const * pViewShell)
     {
         // Just notify pViewShell about our existing selection.
         if (pViewShell != GetShell()->GetSfxViewShell())
-            SfxLokHelper::notifyOtherView(GetShell()->GetSfxViewShell(), 
pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
+            SfxLokHelper::notifyOtherView(*GetShell()->GetSfxViewShell(), 
pViewShell, LOK_CALLBACK_TEXT_VIEW_SELECTION, "selection", sRect);
     }
     else
     {

Reply via email to