sc/source/ui/undo/undotab.cxx |   51 ++++++++++++++++++++----------------------
 1 file changed, 25 insertions(+), 26 deletions(-)

New commits:
commit b227481b63000b556e648ad607ffeb86681482a0
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri May 24 19:30:51 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri May 24 22:34:25 2024 +0200

    pViewShell arg is never null, just use a reference here
    
    Change-Id: I29b5e9084da5b5f0817ffad37e3e5496577372fd
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168029
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins

diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index 3cdeaeed1f76..43f647debbd9 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -63,16 +63,16 @@ using ::std::vector;
 
 namespace
 {
-void lcl_OnTabsChanged(const ScTabViewShell* pViewShell, const ScDocument& 
rDoc, SCTAB nTab, bool bInvalidateTiles = false)
+void lcl_OnTabsChanged(const ScTabViewShell& rViewShell, const ScDocument& 
rDoc, SCTAB nTab, bool bInvalidateTiles = false)
 {
     for (SCTAB nTabIndex = nTab; nTabIndex < rDoc.GetTableCount(); ++nTabIndex)
     {
         if (!rDoc.IsVisible(nTabIndex))
             continue;
         if (bInvalidateTiles)
-            pViewShell->libreOfficeKitViewInvalidateTilesCallback(nullptr, 
nTabIndex, 0);
+            rViewShell.libreOfficeKitViewInvalidateTilesCallback(nullptr, 
nTabIndex, 0);
         ScTabViewShell::notifyAllViewsSheetGeomInvalidation(
-            pViewShell,
+            &rViewShell,
             true /* bColsAffected */, true /* bRowsAffected */,
             true /* bSizes*/, true /* bHidden */, true /* bFiltered */,
             true /* bGroups */, nTabIndex);
@@ -99,7 +99,7 @@ void lcl_MakeJsonArray(tools::JsonWriter& rJson, const 
std::vector<T>& v, const
     }
 }
 
-void lcl_UndoCommandResult(const ScTabViewShell* pViewShell,
+void lcl_UndoCommandResult(const ScTabViewShell& rViewShell,
                            const char *pCmdName, const char *pCmdType,
                            const std::vector<SCTAB>* pNewTabs,
                            const std::vector<SCTAB>* pOldTabs = nullptr)
@@ -116,7 +116,7 @@ void lcl_UndoCommandResult(const ScTabViewShell* pViewShell,
             lcl_MakeJsonArray(aJson, *pOldTabs, "oldTabs");
     }
 
-    pViewShell->libreOfficeKitViewCallback(LOK_CALLBACK_UNO_COMMAND_RESULT, 
aJson.finishAndGetAsOString());
+    rViewShell.libreOfficeKitViewCallback(LOK_CALLBACK_UNO_COMMAND_RESULT, 
aJson.finishAndGetAsOString());
 }
 }
 
@@ -183,9 +183,9 @@ void ScUndoInsertTab::Undo()
     if (comphelper::LibreOfficeKit::isActive())
     {
         ScDocument& rDoc = pDocShell->GetDocument();
-        lcl_OnTabsChanged(pViewShell, rDoc, nTab);
+        lcl_OnTabsChanged(*pViewShell, rDoc, nTab);
         std::vector<SCTAB> aTabs{nTab};
-        lcl_UndoCommandResult(pViewShell, ".uno:Undo", "ScUndoInsertTab", 
&aTabs);
+        lcl_UndoCommandResult(*pViewShell, ".uno:Undo", "ScUndoInsertTab", 
&aTabs);
 
     }
 
@@ -218,9 +218,9 @@ void ScUndoInsertTab::Redo()
     if (comphelper::LibreOfficeKit::isActive())
     {
         ScDocument& rDoc = pDocShell->GetDocument();
-        lcl_OnTabsChanged(pViewShell, rDoc, nTab);
+        lcl_OnTabsChanged(*pViewShell, rDoc, nTab);
         std::vector<SCTAB> aTabs{nTab};
-        lcl_UndoCommandResult(pViewShell, ".uno:Redo", "ScUndoInsertTab", 
&aTabs);
+        lcl_UndoCommandResult(*pViewShell, ".uno:Redo", "ScUndoInsertTab", 
&aTabs);
     }
 }
 
@@ -450,8 +450,8 @@ void ScUndoDeleteTab::Undo()
     {
         if (pViewShell)
         {
-            lcl_OnTabsChanged(pViewShell, rDoc, theTabs[0]);
-            lcl_UndoCommandResult(pViewShell, ".uno:Undo", "ScUndoDeleteTab", 
&theTabs);
+            lcl_OnTabsChanged(*pViewShell, rDoc, theTabs[0]);
+            lcl_UndoCommandResult(*pViewShell, ".uno:Undo", "ScUndoDeleteTab", 
&theTabs);
         }
     }
 
@@ -493,8 +493,8 @@ void ScUndoDeleteTab::Redo()
     if (comphelper::LibreOfficeKit::isActive() && !theTabs.empty())
     {
         ScDocument& rDoc = pDocShell->GetDocument();
-        lcl_OnTabsChanged(pViewShell, rDoc, theTabs[0]);
-        lcl_UndoCommandResult(pViewShell, ".uno:Redo", "ScUndoDeleteTab", 
&theTabs);
+        lcl_OnTabsChanged(*pViewShell, rDoc, theTabs[0]);
+        lcl_UndoCommandResult(*pViewShell, ".uno:Redo", "ScUndoDeleteTab", 
&theTabs);
     }
 
     //  SetTabNo(...,sal_True) for all views to sync with drawing layer pages
@@ -653,8 +653,8 @@ void ScUndoMoveTab::DoChange( bool bUndo ) const
         const auto newTabsMinIt = std::min_element(mpNewTabs->begin(), 
mpNewTabs->end());
         const auto oldTabsMinIt = std::min_element(mpOldTabs->begin(), 
mpOldTabs->end());
         SCTAB nTab = std::min(*newTabsMinIt, *oldTabsMinIt);
-        lcl_OnTabsChanged(pViewShell, rDoc, nTab, true /* bInvalidateTiles */);
-        lcl_UndoCommandResult(pViewShell, bUndo ? ".uno:Undo" : ".uno:Redo", 
"ScUndoMoveTab", mpOldTabs.get(), mpNewTabs.get());
+        lcl_OnTabsChanged(*pViewShell, rDoc, nTab, true /* bInvalidateTiles 
*/);
+        lcl_UndoCommandResult(*pViewShell, bUndo ? ".uno:Undo" : ".uno:Redo", 
"ScUndoMoveTab", mpOldTabs.get(), mpNewTabs.get());
     }
 
     SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );    // 
Navigator
commit 50c718557da8d3141377a10a4a944736111a1494
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Fri May 24 19:28:25 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Fri May 24 22:34:18 2024 +0200

    cid#1598442 Dereference null return value
    
    Change-Id: Id44fb940ba17549068c5be554d5738ce81ced79a
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/168028
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com>

diff --git a/sc/source/ui/undo/undotab.cxx b/sc/source/ui/undo/undotab.cxx
index c12c54bad8ee..3cdeaeed1f76 100644
--- a/sc/source/ui/undo/undotab.cxx
+++ b/sc/source/ui/undo/undotab.cxx
@@ -475,6 +475,9 @@ void ScUndoDeleteTab::Undo()
 void ScUndoDeleteTab::Redo()
 {
     ScTabViewShell* pViewShell = ScTabViewShell::GetActiveViewShell();
+    if (!pViewShell)
+        return;
+
     pViewShell->SetTabNo( lcl_GetVisibleTabBefore( pDocShell->GetDocument(), 
theTabs.front() ) );
 
     RedoSdrUndoAction( pDrawUndo.get() );       // Draw Redo first
@@ -1003,16 +1006,13 @@ void ScUndoImportTab::DoChange() const
 
     ScDocument& rDoc = pDocShell->GetDocument();
     SCTAB nTabCount = rDoc.GetTableCount();
-    if (pViewShell)
+    if(nTab<nTabCount)
     {
-        if(nTab<nTabCount)
-        {
-            pViewShell->SetTabNo(nTab,true);
-        }
-        else
-        {
-            pViewShell->SetTabNo(nTab-1,true);
-        }
+        pViewShell->SetTabNo(nTab,true);
+    }
+    else
+    {
+        pViewShell->SetTabNo(nTab-1,true);
     }
 
     SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );    // 
Navigator
@@ -1231,8 +1231,7 @@ void ScUndoShowHideTab::DoChange( bool bShowP ) const
     for(const SCTAB& nTab : undoTabs)
     {
         rDoc.SetVisible( nTab, bShowP );
-        if (pViewShell)
-            pViewShell->SetTabNo(nTab,true);
+        pViewShell->SetTabNo(nTab,true);
     }
 
     SfxGetpApp()->Broadcast( SfxHint( SfxHintId::ScTablesChanged ) );

Reply via email to