[Libreoffice-commits] core.git: sd/source

Armin Le Grand alg at apache.org
Wed May 22 12:35:49 PDT 2013


 sd/source/ui/slidesorter/model/SlideSorterModel.cxx |   35 ++++++++++++++++----
 1 file changed, 29 insertions(+), 6 deletions(-)

New commits:
commit 5481d32d285178dbf1a974389da1ee7c8ae19939
Author: Armin Le Grand <alg at apache.org>
Date:   Mon Nov 12 16:29:06 2012 +0000

    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

diff --git a/sd/source/ui/slidesorter/model/SlideSorterModel.cxx b/sd/source/ui/slidesorter/model/SlideSorterModel.cxx
index 5b787d4..ca27a7a 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");
 }
 


More information about the Libreoffice-commits mailing list