From 58272b98319c5da2d433c0bc5e520a12ab73c71c Mon Sep 17 00:00:00 2001 From: Markus Mohrhard Date: Thu, 1 Mar 2012 11:07:16 +0100 Subject: fix some iterator misuse in the new notes handling --- sc/source/core/data/table2.cxx | 112 +++++++++++++++++++++++++++++------------ 1 file changed, 80 insertions(+), 32 deletions(-) (limited to 'sc') diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx index 1af4b4940cd1..9f24b476c3e3 100644 --- a/sc/source/core/data/table2.cxx +++ b/sc/source/core/data/table2.cxx @@ -175,18 +175,31 @@ void ScTable::InsertRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE aCol[j].InsertRow( nStartRow, nSize ); ScNotes aNotes(pDocument); - for ( ScNotes::iterator itr = maNotes.begin(); itr != maNotes.end(); ++itr) + ScNotes::iterator itr = maNotes.begin(); + while( itr != maNotes.end() ) { - if (itr->first.second >= nStartRow) + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + if (nCol >= nStartRow) { - aNotes.insert(itr->first.first, itr->first.second + nSize, itr->second); - maNotes.ReleaseNote(itr->first.first, itr->first.second); + aNotes.insert(nCol, nRow + nSize, pPostIt); + maNotes.ReleaseNote(nCol, nRow); } } - for ( ScNotes::iterator itr = aNotes.begin(); itr != aNotes.end(); ++itr) + + itr = aNotes.begin(); + while( itr != aNotes.end() ) { - maNotes.insert( itr->first.first, itr->first.second, itr->second); - aNotes.ReleaseNote(itr->first.first, itr->first.second); + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + maNotes.insert( nCol, nRow, pPostIt); + aNotes.ReleaseNote( nCol, nRow); } DecRecalcLevel( false ); @@ -242,18 +255,31 @@ void ScTable::DeleteRow( SCCOL nStartCol, SCCOL nEndCol, SCROW nStartRow, SCSIZE } ScNotes aNotes(pDocument); - for ( ScNotes::iterator itr = maNotes.begin(); itr != maNotes.end(); ++itr) + ScNotes::iterator itr = maNotes.begin(); + while( itr != maNotes.end() ) { - if (itr->first.second >= nStartRow) + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + if (nCol >= nStartRow) { - aNotes.insert(itr->first.first, itr->first.second - nSize, itr->second); - maNotes.ReleaseNote(itr->first.first, itr->first.second); + aNotes.insert(nCol, nRow - nSize, pPostIt); + maNotes.ReleaseNote(nCol, nRow); } } - for ( ScNotes::iterator itr = aNotes.begin(); itr != aNotes.end(); ++itr) + + itr = aNotes.begin(); + while( itr != aNotes.end() ) { - maNotes.insert( itr->first.first, itr->first.second, itr->second); - aNotes.ReleaseNote(itr->first.first, itr->first.second); + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + maNotes.insert( nCol, nRow, pPostIt); + aNotes.ReleaseNote( nCol, nRow); } { // scope for bulk broadcast @@ -339,20 +365,31 @@ void ScTable::InsertCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE } ScNotes aNotes(pDocument); - for ( ScNotes::iterator itr = maNotes.begin(); itr != maNotes.end(); ++itr) + ScNotes::iterator itr = maNotes.begin(); + while( itr != maNotes.end() ) { - if (itr->first.first > nStartCol) + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + if (nCol >= nStartRow) { - aNotes.insert(itr->first.first + nSize, itr->first.second, itr->second); - maNotes.ReleaseNote(itr->first.first, itr->first.second); + aNotes.insert(nCol + nSize, nRow, pPostIt); + maNotes.ReleaseNote(nCol, nRow); } - else - aNotes.insert( itr->first.first, itr->first.second, itr->second); } - for ( ScNotes::iterator itr = aNotes.begin(); itr != aNotes.end(); ++itr) + + itr = aNotes.begin(); + while( itr != aNotes.end() ) { - maNotes.insert( itr->first.first, itr->first.second, itr->second); - aNotes.ReleaseNote(itr->first.first, itr->first.second); + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + maNotes.insert( nCol, nRow, pPostIt); + aNotes.ReleaseNote( nCol, nRow); } if (nStartCol>0) // copy old attributes @@ -437,20 +474,31 @@ void ScTable::DeleteCol( SCCOL nStartCol, SCROW nStartRow, SCROW nEndRow, SCSIZE } ScNotes aNotes(pDocument); - for ( ScNotes::iterator itr = maNotes.begin(); itr != maNotes.end(); ++itr) + ScNotes::iterator itr = maNotes.begin(); + while( itr != maNotes.end() ) { - if (itr->first.first > nStartCol) + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + if (nCol >= nStartRow) { - aNotes.insert(itr->first.first - nSize, itr->first.second, itr->second); - maNotes.ReleaseNote(itr->first.first, itr->first.second); + aNotes.insert(nCol - nSize, nRow, pPostIt); + maNotes.ReleaseNote(nCol, nRow); } - else - aNotes.insert( itr->first.first, itr->first.second, itr->second); } - for ( ScNotes::iterator itr = aNotes.begin(); itr != aNotes.end(); ++itr) + + itr = aNotes.begin(); + while( itr != aNotes.end() ) { - maNotes.insert( itr->first.first, itr->first.second, itr->second); - aNotes.ReleaseNote(itr->first.first, itr->first.second); + SCCOL nCol = itr->first.first; + SCROW nRow = itr->first.second; + ScPostIt* pPostIt = itr->second; + ++itr; + + maNotes.insert( nCol, nRow, pPostIt); + aNotes.ReleaseNote( nCol, nRow); } DecRecalcLevel(); -- cgit