sc/source/core/data/table1.cxx |   25 ++++++++++++++++++++++---
 1 file changed, 22 insertions(+), 3 deletions(-)

New commits:
commit 6fc75b669438728ba6a4e55d53a79fa0cf006529
Author: Eike Rathke <er...@redhat.com>
Date:   Wed Feb 21 14:53:06 2018 +0100

    Limit ScColumnsRange::Iterator to available columns within bounds
    
    Change-Id: Id5481a975dce99a51cc5619e200e5ea46ad3ad1b
    Reviewed-on: https://gerrit.libreoffice.org/50106
    Reviewed-by: Eike Rathke <er...@redhat.com>
    Tested-by: Jenkins <c...@libreoffice.org>

diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 2e2c2af05aca..ddc440d55fa0 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -2405,9 +2405,28 @@ const ScConditionalFormatList* 
ScTable::GetCondFormList() const
 
 ScColumnsRange ScTable::GetColumnsRange(SCCOL nColBegin, SCCOL nColEnd) const
 {
-    // because the range is inclusive, some code will pass nColEnd<nColBegin 
to indicate an empty range
-    return ScColumnsRange(ScColumnsRange::Iterator(aCol.begin() + nColBegin),
-                          ScColumnsRange::Iterator(nColEnd < nColBegin ? 
(aCol.begin() + nColBegin) : (aCol.begin() + nColEnd + 1)));
+    // Because the range is inclusive, some code will pass nColEnd<nColBegin to
+    // indicate an empty range. Ensure that we create only valid iterators for
+    // the range, limit columns to bounds.
+    SCCOL nEffBegin, nEffEnd;
+    if (nColBegin <= nColEnd)
+    {
+        if (nColBegin < 0)
+            nEffBegin = 0;
+        else
+            nEffBegin = std::min<SCCOL>( nColBegin, aCol.size());
+        if (nColEnd < 0)
+            nEffEnd = 0;
+        else
+            nEffEnd = std::min<SCCOL>( nColEnd + 1, aCol.size());
+    }
+    else
+    {
+        // Any empty will do.
+        nEffBegin = nEffEnd = 0;
+    }
+    return ScColumnsRange( ScColumnsRange::Iterator( aCol.begin() + nEffBegin),
+                           ScColumnsRange::Iterator( aCol.begin() + nEffEnd));
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to