svx/source/svdraw/svdpage.cxx | 22 +++++++++++++++++++--- 1 file changed, 19 insertions(+), 3 deletions(-)
New commits: commit ce22698c762e25157a643ae099e296da25fa0a59 Author: Michael Stahl <michael.st...@cib.de> AuthorDate: Thu Nov 14 18:44:33 2019 +0100 Commit: Caolán McNamara <caol...@redhat.com> CommitDate: Fri Nov 15 09:54:55 2019 +0100 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 <caol...@redhat.com> Tested-by: Caolán McNamara <caol...@redhat.com> 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) { _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits