diff options
author | Luboš Luňák <l.lunak@collabora.com> | 2021-10-06 12:57:15 +0200 |
---|---|---|
committer | Luboš Luňák <l.lunak@collabora.com> | 2021-10-06 16:31:35 +0200 |
commit | e7ec79fe36a0f22f10167806da80e3c1f30b36e8 (patch) | |
tree | f351d73c0486d88a2ab6d56079ed1bd94d34e865 /sc | |
parent | a693009c28059435ea5bae6d89a76e2243fe7793 (diff) |
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.lunak@collabora.com>
Diffstat (limited to 'sc')
-rw-r--r-- | sc/qa/unit/rangelst_test.cxx | 14 | ||||
-rw-r--r-- | sc/source/core/tool/rangelst.cxx | 10 | ||||
-rw-r--r-- | sc/source/ui/unoobj/chart2uno.cxx | 8 |
3 files changed, 27 insertions, 5 deletions
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 d1b7e598c67e..c1b149d7aee5 100644 --- a/sc/source/core/tool/rangelst.cxx +++ b/sc/source/core/tool/rangelst.cxx @@ -436,7 +436,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 3ee4f1cde054..5eb7f2cc75e0 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -2778,7 +2778,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; @@ -2791,7 +2791,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. @@ -2813,7 +2813,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; } @@ -2822,7 +2822,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; } |