summaryrefslogtreecommitdiff
path: root/sc
diff options
context:
space:
mode:
authorEike Rathke <erack@redhat.com>2018-02-21 14:53:06 +0100
committerMarkus Mohrhard <markus.mohrhard@googlemail.com>2018-02-26 11:41:31 +0100
commita16ecbb7a23ef639e3a164383e777ee0eccb399b (patch)
treec827989939039d39e35ca7bd45d8991faca6c3e0 /sc
parent7567beec1f7accf8b6d42ca68fd2c96a6d68ac48 (diff)
Limit ScColumnsRange::Iterator to available columns within bounds
Change-Id: Id5481a975dce99a51cc5619e200e5ea46ad3ad1b Reviewed-on: https://gerrit.libreoffice.org/50106 Reviewed-by: Eike Rathke <erack@redhat.com> Tested-by: Jenkins <ci@libreoffice.org> (cherry picked from commit 6fc75b669438728ba6a4e55d53a79fa0cf006529) Reviewed-on: https://gerrit.libreoffice.org/50125 Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk> Reviewed-by: Markus Mohrhard <markus.mohrhard@googlemail.com>
Diffstat (limited to 'sc')
-rw-r--r--sc/source/core/data/table1.cxx25
1 files changed, 22 insertions, 3 deletions
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 7b275495eb3b..4ce1306258f1 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -2396,9 +2396,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: */