summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorArmin Le Grand <alg@apache.org>2012-11-12 16:29:06 +0000
committerCaolán McNamara <caolanm@redhat.com>2013-05-22 20:37:52 +0100
commit6cf3812ccc56c127fb13ac596ad762423f751316 (patch)
tree6b9f6c4fd0df1359e325bae478f28e57efcd2b0c
parent12da94075c58d7dac7f9a9080107a879de805e89 (diff)
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 (cherry picked from commit 5481d32d285178dbf1a974389da1ee7c8ae19939)
-rw-r--r--sd/source/ui/slidesorter/model/SlideSorterModel.cxx35
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");
}