diff options
author | Michael Stahl <Michael.Stahl@cib.de> | 2019-11-14 18:44:33 +0100 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2019-11-15 09:54:55 +0100 |
commit | ce22698c762e25157a643ae099e296da25fa0a59 (patch) | |
tree | ba470f5cac1297b9b993696e03fedd415485772b | |
parent | 7ecda38cdaa2361e8510bf3e7206863c4936deab (diff) |
tdf#128737 svx: fix off-by-one in SdrObjList::sort()
Increment if the previous one was a text-box, not the current one.
Also add some consistency checks while at it.
(regression from a8b1699ca9c7e8c43eff79467451fd1fcb4fde9b or its
follow-ups)
Change-Id: Iab79e884f4f9cfa358630681495848f4f894506b
Reviewed-on: https://gerrit.libreoffice.org/82724
Tested-by: Jenkins
Reviewed-by: Caolán McNamara <caolanm@redhat.com>
Tested-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r-- | svx/source/svdraw/svdpage.cxx | 22 |
1 files changed, 19 insertions, 3 deletions
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx index d9dd6cc35e42..6fe5f085b25a 100644 --- a/svx/source/svdraw/svdpage.cxx +++ b/svx/source/svdraw/svdpage.cxx @@ -627,6 +627,11 @@ void SdrObjList::sort( std::vector<sal_Int32>& sortOrder) // example aShapesWithTextbox [0 2] } + if (aShapesWithTextbox.size() != maList.size() - sortOrder.size()) + { + throw lang::IllegalArgumentException("mismatch of no. of shapes", nullptr, 0); + } + for (size_t i = 0; i< sortOrder.size(); ++i) { @@ -637,17 +642,19 @@ void SdrObjList::sort( std::vector<sal_Int32>& sortOrder) // example aDuplicates [2 2 0 0 1] } + assert(aDuplicates.size() == maList.size()); aIncrements.push_back(0); for (size_t i = 1; i< sortOrder.size(); ++i) { - if (aShapesWithTextbox.count(i)) + if (aShapesWithTextbox.count(i - 1)) aIncrements.push_back(aIncrements[i-1] + 1 ); else aIncrements.push_back(aIncrements[i-1]); // example aIncrements [0 1 1] } + assert(aIncrements.size() == sortOrder.size()); std::vector<sal_Int32> aNewSortOrder(maList.size()); sal_Int32 nPrev = -1; @@ -662,9 +669,18 @@ void SdrObjList::sort( std::vector<sal_Int32>& sortOrder) // example aNewSortOrder [3 4 0 1 2] } + assert(aNewSortOrder.size() == maList.size()); - if ( aNewSortOrder.size() != maList.size()) - throw css::lang::IllegalArgumentException("mismatch of no. of shapes", nullptr, 0); +#ifndef NDEBUG + { + std::vector<sal_Int32> tmp(aNewSortOrder); + std::sort(tmp.begin(), tmp.end()); + for (size_t i = 0; i < tmp.size(); ++i) + { + assert(size_t(tmp[i]) == i); + } + } +#endif for (size_t i = 0; i < aNewSortOrder.size(); ++i) { |