From b302efec7bb3dbf1de3ef66c2f2098d6d69ba9aa Mon Sep 17 00:00:00 2001 From: Dennis Francis Date: Fri, 2 Jul 2021 19:01:47 +0530 Subject: lok: sc: avoid crash on non existent tab view data ... when accessing position helpers. Change-Id: Ia627a8c4ed30ad1f1c2333df00b656fe041f111e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/118318 Tested-by: Jenkins CollaboraOffice Reviewed-by: Michael Meeks --- sc/source/ui/docshell/docfunc.cxx | 3 ++- sc/source/ui/view/dbfunc3.cxx | 10 ++++++++-- sc/source/ui/view/viewdata.cxx | 6 ++++-- sc/source/ui/view/viewfunc.cxx | 16 ++++++++++++---- 4 files changed, 26 insertions(+), 9 deletions(-) diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx index 38af064a918c..15a57dc42400 100644 --- a/sc/source/ui/docshell/docfunc.cxx +++ b/sc/source/ui/docshell/docfunc.cxx @@ -161,7 +161,8 @@ bool ScDocFunc::AdjustRowHeight( const ScRange& rRange, bool bPaint ) ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); if (pTabViewShell) { - pTabViewShell->GetViewData().GetLOKHeightHelper(nTab)->invalidateByIndex(nStartRow); + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKHeightHelper(nTab)) + pPosHelper->invalidateByIndex(nStartRow); } pViewShell = SfxViewShell::GetNext(*pViewShell); } diff --git a/sc/source/ui/view/dbfunc3.cxx b/sc/source/ui/view/dbfunc3.cxx index d1f57b46dead..c7f7d81a8a9e 100644 --- a/sc/source/ui/view/dbfunc3.cxx +++ b/sc/source/ui/view/dbfunc3.cxx @@ -2260,9 +2260,15 @@ void ScDBFunc::OnLOKShowHideColRow(bool bColumns, SCCOLROW nStart) if (pTabViewShell) { if (bColumns) - pTabViewShell->GetViewData().GetLOKWidthHelper(nCurrentTabIndex)->invalidateByIndex(nStart); + { + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKWidthHelper(nCurrentTabIndex)) + pPosHelper->invalidateByIndex(nStart); + } else - pTabViewShell->GetViewData().GetLOKHeightHelper(nCurrentTabIndex)->invalidateByIndex(nStart); + { + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKHeightHelper(nCurrentTabIndex)) + pPosHelper->invalidateByIndex(nStart); + } if (pTabViewShell->getPart() == nCurrentTabIndex) { diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx index 1c7e36ca484a..39f23fb31f62 100644 --- a/sc/source/ui/view/viewdata.cxx +++ b/sc/source/ui/view/viewdata.cxx @@ -1996,7 +1996,8 @@ void ScViewData::SetTabNo( SCTAB nNewTab ) ScPositionHelper* ScViewData::GetLOKWidthHelper(SCTAB nTabIndex) { - if (!ValidTab(nTabIndex) || (nTabIndex >= static_cast(maTabData.size()))) + if (!ValidTab(nTabIndex) || (nTabIndex >= static_cast(maTabData.size())) || + !maTabData[nTabIndex]) { return nullptr; } @@ -2005,7 +2006,8 @@ ScPositionHelper* ScViewData::GetLOKWidthHelper(SCTAB nTabIndex) ScPositionHelper* ScViewData::GetLOKHeightHelper(SCTAB nTabIndex) { - if (!ValidTab(nTabIndex) || (nTabIndex >= static_cast(maTabData.size()))) + if (!ValidTab(nTabIndex) || (nTabIndex >= static_cast(maTabData.size())) || + !maTabData[nTabIndex]) { return nullptr; } diff --git a/sc/source/ui/view/viewfunc.cxx b/sc/source/ui/view/viewfunc.cxx index a0e1185a6d3f..51738b4951af 100644 --- a/sc/source/ui/view/viewfunc.cxx +++ b/sc/source/ui/view/viewfunc.cxx @@ -1487,7 +1487,8 @@ void ScViewFunc::OnLOKInsertDeleteColumn(SCCOL nStartCol, long nOffset) ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); if (pTabViewShell) { - pTabViewShell->GetViewData().GetLOKWidthHelper(nCurrentTabIndex)->invalidateByIndex(nStartCol); + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKWidthHelper(nCurrentTabIndex)) + pPosHelper->invalidateByIndex(nStartCol); // if we remove a column the cursor position and the current selection // in other views could need to be moved on the left by one column. @@ -1542,7 +1543,8 @@ void ScViewFunc::OnLOKInsertDeleteRow(SCROW nStartRow, long nOffset) ScTabViewShell* pTabViewShell = dynamic_cast(pViewShell); if (pTabViewShell) { - pTabViewShell->GetViewData().GetLOKHeightHelper(nCurrentTabIndex)->invalidateByIndex(nStartRow); + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKHeightHelper(nCurrentTabIndex)) + pPosHelper->invalidateByIndex(nStartRow); // if we remove a row the cursor position and the current selection // in other views could need to be moved up by one row. @@ -1598,9 +1600,15 @@ void ScViewFunc::OnLOKSetWidthOrHeight(SCCOLROW nStart, bool bWidth) if (pTabViewShell) { if (bWidth) - pTabViewShell->GetViewData().GetLOKWidthHelper(nCurTab)->invalidateByIndex(nStart); + { + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKWidthHelper(nCurTab)) + pPosHelper->invalidateByIndex(nStart); + } else - pTabViewShell->GetViewData().GetLOKHeightHelper(nCurTab)->invalidateByIndex(nStart); + { + if (ScPositionHelper* pPosHelper = pTabViewShell->GetViewData().GetLOKHeightHelper(nCurTab)) + pPosHelper->invalidateByIndex(nStart); + } } pViewShell = SfxViewShell::GetNext(*pViewShell); } -- cgit