diff options
author | Eike Rathke <erack@redhat.com> | 2018-02-21 14:53:06 +0100 |
---|---|---|
committer | Eike Rathke <erack@redhat.com> | 2018-02-21 20:56:18 +0100 |
commit | 6fc75b669438728ba6a4e55d53a79fa0cf006529 (patch) | |
tree | 0dc7db4cc5a3eea198d62eeda7916757acb8d8d8 | |
parent | 55b310e785ed5fbdfb2996764751334dbb6fecdd (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>
-rw-r--r-- | sc/source/core/data/table1.cxx | 25 |
1 files changed, 22 insertions, 3 deletions
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: */ |