sfx2/source/control/unoctitm.cxx |   18 +++++++++++-------
 1 file changed, 11 insertions(+), 7 deletions(-)

New commits:
commit 1e605412df2ca9aab895b34f256ccd5a8dfdc83d
Author:     Miklos Vajna <vmik...@collabora.com>
AuthorDate: Fri Apr 12 08:52:43 2024 +0200
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Sat Apr 13 16:52:50 2024 +0200

    sfx2: fix crash in InterceptLOKStateChangeEvent()
    
    Notice how e.g. the TransformPosX case already performed the same null
    pointer check.
    
    Crashreport backtrace:
    
    > program/libmergedlo.so
    >       InterceptLOKStateChangeEvent
    >               sfx2/source/control/unoctitm.cxx:1143
    > program/libmergedlo.so
    >       SfxStateCache::SetState_Impl(SfxItemState, SfxPoolItem const*, bool)
    >               sfx2/source/control/statcach.cxx:432
    > program/libmergedlo.so
    >       SfxBindings::Update_Impl(SfxStateCache&)
    >               
/opt/rh/devtoolset-10/root/usr/include/c++/10/bits/stl_vector.h:919 
(discriminator 2)
    > program/libmergedlo.so
    >       SfxBindings::NextJob_Impl(Timer const*)
    >               
/opt/rh/devtoolset-10/root/usr/include/c++/10/bits/unique_ptr.h:173
    
    Change-Id: I141d4f9ec50d0ce7a0eeaba69752c31390a1f9ba
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166027
    Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com>
    Reviewed-by: Michael Meeks <michael.me...@collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166046
    Tested-by: Jenkins
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sfx2/source/control/unoctitm.cxx b/sfx2/source/control/unoctitm.cxx
index 333879c24d0f..f49dc2d7336f 100644
--- a/sfx2/source/control/unoctitm.cxx
+++ b/sfx2/source/control/unoctitm.cxx
@@ -1118,13 +1118,17 @@ static void InterceptLOKStateChangeEvent(sal_uInt16 
nSID, SfxViewFrame* pViewFra
     else if (aEvent.FeatureURL.Path == "ParaLeftToRight" ||
              aEvent.FeatureURL.Path == "ParaRightToLeft")
     {
-        tools::JsonWriter aTree;
-        bool bTemp = false;
-        aEvent.State >>= bTemp;
-        aTree.put("commandName", aEvent.FeatureURL.Complete);
-        aTree.put("disabled", !aEvent.IsEnabled);
-        aTree.put("state", bTemp ? "true" : "false");
-        
SfxViewShell::Current()->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
aTree.finishAndGetAsOString());
+        const SfxViewShell* pViewShell = SfxViewShell::Current();
+        if (pViewShell)
+        {
+            tools::JsonWriter aTree;
+            bool bTemp = false;
+            aEvent.State >>= bTemp;
+            aTree.put("commandName", aEvent.FeatureURL.Complete);
+            aTree.put("disabled", !aEvent.IsEnabled);
+            aTree.put("state", bTemp ? "true" : "false");
+            pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_STATE_CHANGED, 
aTree.finishAndGetAsOString());
+        }
         return;
     }
     else if (aEvent.FeatureURL.Path == "AssignLayout" ||

Reply via email to