sc/qa/unit/rangelst_test.cxx | 14 ++++++++++++++ sc/source/core/tool/rangelst.cxx | 10 +++++++++- sc/source/ui/unoobj/chart2uno.cxx | 8 ++++---- 3 files changed, 27 insertions(+), 5 deletions(-)
New commits: commit c20d606c9c04e5c4092e059c43a292264e3bf12f Author: Luboš Luňák <l.lu...@collabora.com> AuthorDate: Wed Oct 6 12:57:15 2021 +0200 Commit: Luboš Luňák <l.lu...@collabora.com> CommitDate: Thu Oct 14 11:51:33 2021 +0200 ScRangeList::UpdateReference() join all ranges properly (tdf#140901) This is basically a revert of 6eb8634a9f62bfe486ecd2f46, which made this Join() just the last range, probably under the assumption that the function is always called with just one range to update, or to avoid the possibility that Join() removes several items from the list, breaking the next step of the loop. But DeleteArea() may split several ranges, so we need to make sure to Join() all of them. Change-Id: Iea124142335ccdc8fa578344cddce8670c27573d Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123135 Tested-by: Jenkins Reviewed-by: Luboš Luňák <l.lu...@collabora.com> (cherry picked from commit e7ec79fe36a0f22f10167806da80e3c1f30b36e8) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/123519 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> diff --git a/sc/qa/unit/rangelst_test.cxx b/sc/qa/unit/rangelst_test.cxx index bfd4acd5dae1..4239cc91e8a9 100644 --- a/sc/qa/unit/rangelst_test.cxx +++ b/sc/qa/unit/rangelst_test.cxx @@ -520,6 +520,20 @@ void Test::testUpdateReference_DeleteRow() ScRangeList aList2(ScRange(2,2,0,2,2,0)); aList2.UpdateReference(URM_INSDEL, m_pDoc, ScRange(0,3,0,MAXCOL,MAXROW,0), 0, -1, 0); CPPUNIT_ASSERT(aList2.empty()); + + ScRangeList aList3; + aList3.push_back(ScRange(2,2,0,2,8,0)); + aList3.push_back(ScRange(4,2,0,4,8,0)); + aList3.UpdateReference(URM_INSDEL, m_pDoc, ScRange(2,5,0,MAXCOL,MAXROW,0), 0, -1, 0); + // Verify all ranges in the list have been updated properly. + CPPUNIT_ASSERT_EQUAL(size_t(2), aList3.size()); + CPPUNIT_ASSERT_EQUAL(ScRange(2,2,0,2,7,0), aList3[0]); + CPPUNIT_ASSERT_EQUAL(ScRange(4,2,0,4,7,0), aList3[1]); + + ScRangeList aList4(ScRange(0,0,0,MAXCOL,MAXROW,0)); + ScRangeList aList4Copy = aList4; + aList4.UpdateReference(URM_INSDEL, m_pDoc, ScRange(14,3,0,MAXCOL,7,0), 0, -2, 0); + CPPUNIT_ASSERT_EQUAL(aList4Copy, aList4); } void Test::testUpdateReference_DeleteLastRow() diff --git a/sc/source/core/tool/rangelst.cxx b/sc/source/core/tool/rangelst.cxx index c49e9694c0c8..eb1ad4fc37e5 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -438,7 +438,15 @@ bool ScRangeList::UpdateReference( if( nDx < 0 || nDy < 0 ) { size_t n = maRanges.size(); - Join(maRanges[n-1], true); + for(size_t i = n-1; i > 0;) + { + Join(maRanges[i], true); + // Join() may merge and remove even more than one item, protect against it. + if(i >= maRanges.size()) + i = maRanges.size()-1; + else + --i; + } } } diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx index c8bc1fc77996..437157aa050c 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -2716,7 +2716,7 @@ void ScChart2DataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint } } - OSL_ENSURE(m_pRangeIndices->size() == aRanges.size(), + assert(m_pRangeIndices->size() == aRanges.size() && "range list and range index list have different sizes."); unique_ptr<ScRangeList> pUndoRanges; @@ -2729,7 +2729,7 @@ void ScChart2DataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint if (bChanged) { - OSL_ENSURE(m_pRangeIndices->size() == aRanges.size(), + assert(m_pRangeIndices->size() == aRanges.size() && "range list and range index list have different sizes after the reference update."); // Bring the change back from the range list to the token list. @@ -2751,7 +2751,7 @@ void ScChart2DataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint if (!m_pRangeIndices || m_pRangeIndices->empty()) { - OSL_FAIL(" faulty range indices"); + assert(false && " faulty range indices"); break; } @@ -2760,7 +2760,7 @@ void ScChart2DataSequence::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint size_t nCount = rRanges.size(); if (nCount != m_pRangeIndices->size()) { - OSL_FAIL("range count and range index count differ."); + assert(false && "range count and range index count differ."); break; }