diff options
author | David Tardon <dtardon@redhat.com> | 2011-05-23 07:38:02 +0200 |
---|---|---|
committer | David Tardon <dtardon@redhat.com> | 2011-05-23 07:38:02 +0200 |
commit | 66ac561d255ab92a43dcf933ac9bc76577ba7659 (patch) | |
tree | ee6c9fc0cfe0d38010f3b00aefefb3dac6c16827 | |
parent | 0fd5c0237e0fcfe481371c6f5b95d51f35e4bd17 (diff) |
compensate for already shifted segments
-rw-r--r-- | sc/source/core/data/column3.cxx | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/sc/source/core/data/column3.cxx b/sc/source/core/data/column3.cxx index 25706e6e2..c281a3503 100644 --- a/sc/source/core/data/column3.cxx +++ b/sc/source/core/data/column3.cxx @@ -526,6 +526,11 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe { SCSIZE nStartSegment(aIt->first); bool bMoveSegment(aIt->second); + // The indexes in aRemovedSegments denote cell positions in the + // original array. But as we are shifting it from the left, we have + // to compensate for already performed shifts for latter segments. + // TODO: use reverse iterators instead + SCSIZE nShift(0); ++aIt; do { @@ -533,9 +538,12 @@ void ScColumn::DeleteRange( SCSIZE nStartIndex, SCSIZE nEndIndex, sal_uInt16 nDe if (bMoveSegment) { memmove( - &pItems[nStartSegment], &pItems[nEndSegment], + &pItems[nStartSegment - nShift], + &pItems[nEndSegment - nShift], (nCount - nEndSegment) * sizeof(ColEntry)); - nCount -= nEndSegment - nStartSegment; + SCSIZE const nNewShift(nEndSegment - nStartSegment); + nShift += nNewShift; + nCount -= nNewShift; } nStartSegment = nEndSegment; bMoveSegment = aIt->second; |