diff options
author | Armin Le Grand <alg@apache.org> | 2012-11-12 16:29:06 +0000 |
---|---|---|
committer | Caolán McNamara <caolanm@redhat.com> | 2013-05-22 20:35:10 +0100 |
commit | 5481d32d285178dbf1a974389da1ee7c8ae19939 (patch) | |
tree | 730429dcdc563c8de6e79e7dbd9a732aeb933662 /sd | |
parent | Updated core (diff) | |
download | core-5481d32d285178dbf1a974389da1ee7c8ae19939.tar.gz core-5481d32d285178dbf1a974389da1ee7c8ae19939.zip |
Secured SlideSorterModel::DeleteSlide for negative page indices
(cherry picked from commit f6bff98d6f13bf71fc4bce53c189598c002343c2)
Change-Id: I8c7ca633043ec224df4e4ab08c20d44f969a8059
Corrected signed/unsigned mix
(cherry picked from commit 20a3aee5359f143a6e4bf0bcb7fdef4675b3dd83)
Change-Id: I6f8ffc6f541c2a06c9e97ef06711f312adc438f2
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/ui/slidesorter/model/SlideSorterModel.cxx | 35 |
1 files changed, 29 insertions, 6 deletions
diff --git a/sd/source/ui/slidesorter/model/SlideSorterModel.cxx b/sd/source/ui/slidesorter/model/SlideSorterModel.cxx index 5b787d4874f7..ca27a7acc6cf 100644 --- a/sd/source/ui/slidesorter/model/SlideSorterModel.cxx +++ b/sd/source/ui/slidesorter/model/SlideSorterModel.cxx @@ -670,13 +670,36 @@ void SlideSorterModel::InsertSlide (SdPage* pPage) void SlideSorterModel::DeleteSlide (const SdPage* pPage) { - const sal_Int32 nIndex (GetIndex(pPage)); - if (maPageDescriptors[nIndex]) - if (maPageDescriptors[nIndex]->GetPage() != pPage) - return; + sal_Int32 nIndex(0); - maPageDescriptors.erase(maPageDescriptors.begin()+nIndex); - UpdateIndices(nIndex); + // Caution, GetIndex() may be negative since it uses GetPageNumber()-1 + // for calculation, so do this only when page is inserted, else the + // GetPageNumber() will be zero and thus GetIndex() == -1 + if(pPage->IsInserted()) + { + nIndex = GetIndex(pPage); + } + else + { + // if not inserted, search for page + for(; nIndex < static_cast<sal_Int32>(maPageDescriptors.size()); nIndex++) + { + if(maPageDescriptors[nIndex]->GetPage() == pPage) + { + break; + } + } + } + + if(nIndex >= 0 && nIndex < static_cast<sal_Int32>(maPageDescriptors.size())) + { + if (maPageDescriptors[nIndex]) + if (maPageDescriptors[nIndex]->GetPage() != pPage) + return; + + maPageDescriptors.erase(maPageDescriptors.begin()+nIndex); + UpdateIndices(nIndex); + } OSL_TRACE("page removed"); } |