sc/source/ui/view/tabvwshb.cxx |   53 +++++++++++++++++++++++++----------------
 1 file changed, 33 insertions(+), 20 deletions(-)

New commits:
commit 89581c26be049b5af5bda96f21e908df81a1a194
Author:     Noel Grandin <noel.gran...@collabora.co.uk>
AuthorDate: Sat Aug 13 18:07:58 2022 +0200
Commit:     Noel Grandin <noel.gran...@collabora.co.uk>
CommitDate: Sat Aug 13 20:23:05 2022 +0200

    fix UBSAN downcast...does not point to an object of type 'ScUndoManager'
    
    after
        commit 640a6488a32e8f682788feb6cab01acfffca7fa7
        Date:   Thu Jul 28 19:06:59 2022 +0200
        sc: allow undo of typing in 2 views independent from each other
    
    /sc/source/ui/view/tabvwshb.cxx:815:35: runtime error: downcast of
    address 0x6030007d3c20 which does not point to an object of type
    'ScUndoManager'
    0x6030007d3c20: note: object is of type 'EditUndoManager'
    00 00 00 00  30 0a 0d 67 ed 7f 00 00  d0 d6 11 00 f0 60 00 00  40 7b b7
    00 c0 60 00 00  00 00 00 00
                  ^~~~~~~~~~~~~~~~~~~~~~~
                  vptr for 'EditUndoManager'
    /sc/source/ui/view/tabvwshb.cxx:815:35
    SfxItemSet&) /workdir/SdiTarget/sc/sdi/scslots.hxx:1456:1
    SfxItemSet&, SfxSlot const*) /sfx2/source/control/dispatch.cxx:1658:9
    /sfx2/source/control/bindings.cxx:260:22
    /sfx2/source/control/bindings.cxx:1275:17
    /sfx2/source/control/bindings.cxx:1220:5
    /sfx2/sour
    
    Change-Id: I4a505132184800a26725d602d3e27d1094e3ff65
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/138233
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/ui/view/tabvwshb.cxx b/sc/source/ui/view/tabvwshb.cxx
index 2b1a96f919d1..a26c126c84bd 100644
--- a/sc/source/ui/view/tabvwshb.cxx
+++ b/sc/source/ui/view/tabvwshb.cxx
@@ -812,7 +812,8 @@ void ScTabViewShell::ExecuteUndo(SfxRequest& rReq)
 void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
 {
     SfxShell* pSh = GetViewData().GetDispatcher().GetShell(0);
-    ScUndoManager* pUndoManager = 
static_cast<ScUndoManager*>(pSh->GetUndoManager());
+    SfxUndoManager* pUndoManager = pSh->GetUndoManager();
+    ScUndoManager* pScUndoManager = dynamic_cast<ScUndoManager*>(pUndoManager);
 
     SfxWhichIter aIter(rSet);
     sal_uInt16 nWhich = aIter.FirstWhich();
@@ -841,41 +842,53 @@ void ScTabViewShell::GetUndoState(SfxItemSet &rSet)
 
             case SID_UNDO:
             {
-                if (pUndoManager->GetUndoActionCount())
+                if (pScUndoManager)
                 {
-                    const SfxUndoAction* pAction = 
pUndoManager->GetUndoAction();
-                    SfxViewShell *pViewSh = GetViewShell();
-                    if (pViewSh && pAction->GetViewShellId() != 
pViewSh->GetViewShellId()
-                        && !pUndoManager->IsViewUndoActionIndependent(this, 
o3tl::temporary(sal_uInt16())))
+                    if (pScUndoManager->GetUndoActionCount())
                     {
-                        rSet.Put(SfxUInt32Item(SID_UNDO, 
static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+                        const SfxUndoAction* pAction = 
pScUndoManager->GetUndoAction();
+                        SfxViewShell *pViewSh = GetViewShell();
+                        if (pViewSh && pAction->GetViewShellId() != 
pViewSh->GetViewShellId()
+                            && 
!pScUndoManager->IsViewUndoActionIndependent(this, 
o3tl::temporary(sal_uInt16())))
+                        {
+                            rSet.Put(SfxUInt32Item(SID_UNDO, 
static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+                        }
+                        else
+                        {
+                            rSet.Put( SfxStringItem( SID_UNDO, 
SvtResId(STR_UNDO)+pScUndoManager->GetUndoActionComment() ) );
+                        }
                     }
                     else
-                    {
-                        rSet.Put( SfxStringItem( SID_UNDO, 
SvtResId(STR_UNDO)+pUndoManager->GetUndoActionComment() ) );
-                    }
+                        rSet.DisableItem( SID_UNDO );
                 }
                 else
-                    rSet.DisableItem( SID_UNDO );
+                    // get state from sfx view frame
+                    GetViewFrame()->GetSlotState( nWhich, nullptr, &rSet );
                 break;
             }
             case SID_REDO:
             {
-                if (pUndoManager->GetRedoActionCount())
+                if (pScUndoManager)
                 {
-                    const SfxUndoAction* pAction = 
pUndoManager->GetRedoAction();
-                    SfxViewShell *pViewSh = GetViewShell();
-                    if (pViewSh && pAction->GetViewShellId() != 
pViewSh->GetViewShellId())
+                    if (pScUndoManager->GetRedoActionCount())
                     {
-                        rSet.Put(SfxUInt32Item(SID_REDO, 
static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+                        const SfxUndoAction* pAction = 
pScUndoManager->GetRedoAction();
+                        SfxViewShell *pViewSh = GetViewShell();
+                        if (pViewSh && pAction->GetViewShellId() != 
pViewSh->GetViewShellId())
+                        {
+                            rSet.Put(SfxUInt32Item(SID_REDO, 
static_cast<sal_uInt32>(SID_REPAIRPACKAGE)));
+                        }
+                        else
+                        {
+                            rSet.Put(SfxStringItem(SID_REDO, 
SvtResId(STR_REDO) + pScUndoManager->GetRedoActionComment()));
+                        }
                     }
                     else
-                    {
-                        rSet.Put(SfxStringItem(SID_REDO, SvtResId(STR_REDO) + 
pUndoManager->GetRedoActionComment()));
-                    }
+                        rSet.DisableItem( SID_REDO );
                 }
                 else
-                    rSet.DisableItem( SID_REDO );
+                    // get state from sfx view frame
+                    GetViewFrame()->GetSlotState( nWhich, nullptr, &rSet );
                 break;
             }
             default:

Reply via email to