[Libreoffice-commits] .: 2 commits - editeng/source

Michael Stahl mst at kemper.freedesktop.org
Fri Feb 3 05:21:39 PST 2012


 editeng/source/editeng/edtspell.cxx |   65 ++++++++++++++++++++----------------
 1 file changed, 37 insertions(+), 28 deletions(-)

New commits:
commit 874f2e53b24ad24d4e99f0df54ba6539d1958371
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 3 14:19:47 2012 +0100

    WrongList::TextInserted: fix STL crash
    
    vector iterators and insert don't mix well
    (regression from dfbf0cabfa8310502e19642d56c746cc0d454d27)

diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx
index f13fb1a..eda0d61 100644
--- a/editeng/source/editeng/edtspell.cxx
+++ b/editeng/source/editeng/edtspell.cxx
@@ -242,48 +242,51 @@ void WrongList::TextInserted( sal_uInt16 nPos, sal_uInt16 nNew, sal_Bool bPosIsS
             nInvalidEnd = nPos+nNew;
     }
 
-    for (WrongList::iterator i = begin(); i != end(); ++i)
+    for (WrongList::size_type i = 0; i < size(); ++i)
     {
+        WrongRange & rWrong = (*this)[i]; // why does this thing derive vector?
         sal_Bool bRefIsValid = sal_True;
-        if (i->nEnd >= nPos)
+        if (rWrong.nEnd >= nPos)
         {
             // Move all Wrongs after the insert position...
-            if (i->nStart > nPos)
+            if (rWrong.nStart > nPos)
             {
-                i->nStart += nNew;
-                i->nEnd += nNew;
+                rWrong.nStart += nNew;
+                rWrong.nEnd += nNew;
             }
             // 1: Starts before and goes until nPos...
-            else if (i->nEnd == nPos)
+            else if (rWrong.nEnd == nPos)
             {
                 // Should be halted at a blank!
                 if ( !bPosIsSep )
-                    i->nEnd += nNew;
+                    rWrong.nEnd += nNew;
             }
             // 2: Starts before and goes until after nPos...
-            else if (i->nStart < nPos && i->nEnd > nPos)
+            else if ((rWrong.nStart < nPos) && (rWrong.nEnd > nPos))
             {
-                i->nEnd += nNew;
+                rWrong.nEnd += nNew;
                 // When a separator remove and re-examine the Wrong
                 if ( bPosIsSep )
                 {
                     // Split Wrong...
-                    WrongRange aNewWrong(i->nStart, nPos);
-                    i->nStart = nPos + 1;
-                    insert(i, aNewWrong);
-                    bRefIsValid = sal_False;    // Reference no longer valid after Insert, the other was inserted in front of this position
+                    WrongRange aNewWrong(rWrong.nStart, nPos);
+                    rWrong.nStart = nPos + 1;
+                    insert(begin() + i, aNewWrong);
+                    // Reference no longer valid after Insert, the other
+                    // was inserted in front of this position
+                    bRefIsValid = false;
                     ++i; // Not this again...
                 }
             }
             // 3: Attribute starts at position ..
-            else if (i->nStart == nPos)
+            else if (rWrong.nStart == nPos)
             {
-                i->nEnd += nNew;
+                rWrong.nEnd += nNew;
                 if ( bPosIsSep )
-                    ++(i->nStart);
+                    ++(rWrong.nStart);
             }
         }
-        SAL_WARN_IF(bRefIsValid && i->nStart >= i->nEnd, "editeng",
+        SAL_WARN_IF(bRefIsValid && rWrong.nStart >= rWrong.nEnd, "editeng",
                 "TextInserted, WrongRange: Start >= End?!");
         (void)bRefIsValid;
     }
commit aa2333374d8f587afa9e876334a1b6303bcec0a9
Author: Michael Stahl <mstahl at redhat.com>
Date:   Fri Feb 3 13:34:07 2012 +0100

    editeng: convert some DBG_ASSERTs

diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx
index 77a65dd..f13fb1a 100644
--- a/editeng/source/editeng/edtspell.cxx
+++ b/editeng/source/editeng/edtspell.cxx
@@ -55,7 +55,7 @@ EditSpellWrapper::EditSpellWrapper( Window* _pWin,
         sal_Bool bIsStart, sal_Bool bIsAllRight, EditView* pView ) :
     SvxSpellWrapper( _pWin, xChecker, bIsStart, bIsAllRight )
 {
-    DBG_ASSERT( pView, "One view has to be abandoned!" );
+    SAL_WARN_IF( !pView, "editeng", "One view has to be abandoned!" );
     // Keep IgnoreList, delete ReplaceList...
     if (SvxGetChangeAllList().is())
         SvxGetChangeAllList()->clear();
@@ -283,11 +283,12 @@ void WrongList::TextInserted( sal_uInt16 nPos, sal_uInt16 nNew, sal_Bool bPosIsS
                     ++(i->nStart);
             }
         }
-        DBG_ASSERT(!bRefIsValid || i->nStart < i->nEnd, "TextInserted, WrongRange: Start >= End?!");
+        SAL_WARN_IF(bRefIsValid && i->nStart >= i->nEnd, "editeng",
+                "TextInserted, WrongRange: Start >= End?!");
         (void)bRefIsValid;
     }
 
-    DBG_ASSERT( !DbgIsBuggy(), "InsertWrong: WrongList broken!" );
+    SAL_WARN_IF(DbgIsBuggy(), "editeng", "InsertWrong: WrongList broken!");
 }
 
 void WrongList::TextDeleted( sal_uInt16 nPos, sal_uInt16 nDeleted )
@@ -343,7 +344,8 @@ void WrongList::TextDeleted( sal_uInt16 nPos, sal_uInt16 nDeleted )
                 i->nEnd -= nDeleted;
             }
         }
-        DBG_ASSERT(i->nStart < i->nEnd, "TextInserted, WrongRange: Start >= End?!" );
+        SAL_WARN_IF(i->nStart >= i->nEnd, "editeng",
+                "TextDeleted, WrongRange: Start >= End?!");
         if ( bDelWrong )
         {
             i = erase(i);
@@ -354,7 +356,7 @@ void WrongList::TextDeleted( sal_uInt16 nPos, sal_uInt16 nDeleted )
         }
     }
 
-    DBG_ASSERT( !DbgIsBuggy(), "InsertWrong: WrongList broken!" );
+    SAL_WARN_IF(DbgIsBuggy(), "editeng", "TextDeleted: WrongList broken!");
 }
 
 sal_Bool WrongList::NextWrong( sal_uInt16& rnStart, sal_uInt16& rnEnd ) const
@@ -430,7 +432,7 @@ void WrongList::ClearWrongs( sal_uInt16 nStart, sal_uInt16 nEnd,
         }
     }
 
-    DBG_ASSERT( !DbgIsBuggy(), "InsertWrong: WrongList broken!" );
+    SAL_WARN_IF(DbgIsBuggy(), "editeng", "ClearWrongs: WrongList broken!");
 }
 
 void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd,
@@ -448,7 +450,7 @@ void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd,
                 // and runs along, but not that there are several ranges ...
                 // Exactly in the range is no one allowed to be, otherwise this
                 // Method can not be called!
-                DBG_ASSERT((i->nStart == nStart && i->nEnd > nEnd) || i->nStart > nEnd, "InsertWrong: RangeMismatch!");
+                SAL_WARN_IF((i->nStart != nStart || i->nEnd <= nEnd) && i->nStart <= nEnd, "editeng", "InsertWrong: RangeMismatch!");
                 if (i->nStart == nStart && i->nEnd > nEnd)
                     i->nStart = nEnd + 1;
             }
@@ -461,7 +463,7 @@ void WrongList::InsertWrong( sal_uInt16 nStart, sal_uInt16 nEnd,
     else
         push_back(WrongRange(nStart, nEnd));
 
-    DBG_ASSERT( !DbgIsBuggy(), "InsertWrong: WrongList broken!" );
+    SAL_WARN_IF(DbgIsBuggy(), "editeng", "InsertWrong: WrongList broken!");
 }
 
 void WrongList::MarkWrongsInvalid()
@@ -544,7 +546,8 @@ sal_Bool EdtAutoCorrDoc::Delete( sal_uInt16 nStt, sal_uInt16 nEnd )
 {
     EditSelection aSel( EditPaM( pCurNode, nStt ), EditPaM( pCurNode, nEnd ) );
     pImpEE->ImpDeleteSelection( aSel );
-    DBG_ASSERT( nCursor >= nEnd, "Cursor in the heart of the action?!" );
+    SAL_WARN_IF(nCursor < nEnd, "editeng",
+            "Cursor in the heart of the action?!");
     nCursor -= ( nEnd-nStt );
     bAllowUndoAction = sal_False;
     return sal_True;
@@ -554,7 +557,8 @@ sal_Bool EdtAutoCorrDoc::Insert( sal_uInt16 nPos, const String& rTxt )
 {
     EditSelection aSel = EditPaM( pCurNode, nPos );
     pImpEE->ImpInsertText( aSel, rTxt );
-    DBG_ASSERT( nCursor >= nPos, "Cursor in the heart of the action?!" );
+    SAL_WARN_IF(nCursor < nPos, "editeng",
+            "Cursor in the heart of the action?!");
     nCursor = nCursor + rTxt.Len();
 
     if ( bAllowUndoAction && ( rTxt.Len() == 1 ) )
@@ -624,7 +628,8 @@ sal_Bool EdtAutoCorrDoc::SetINetAttr( sal_uInt16 nStt, sal_uInt16 nEnd,
     EditSelection aSel( EditPaM( pCurNode, nStt ), EditPaM( pCurNode, nEnd ) );
     String aText = pImpEE->GetSelected( aSel );
     aSel = pImpEE->ImpDeleteSelection( aSel );
-    DBG_ASSERT( nCursor >= nEnd, "Cursor in the heart of the action ?!" );
+    SAL_WARN_IF(nCursor < nEnd, "editeng",
+            "Cursor in the heart of the action?!");
     nCursor -= ( nEnd-nStt );
     SvxFieldItem aField( SvxURLField( rURL, aText, SVXURLFORMAT_REPR ),
                                       EE_FEATURE_FIELD  );
@@ -717,7 +722,8 @@ sal_Bool EdtAutoCorrDoc::ChgAutoCorrWord( sal_uInt16& rSttPos,
         EditSelection aSel( EditPaM( pCurNode, rSttPos ),
                             EditPaM( pCurNode, nEndPos ) );
         aSel = pImpEE->ImpDeleteSelection( aSel );
-        DBG_ASSERT( nCursor >= nEndPos, "Cursor in the heart of the action?!" );
+        SAL_WARN_IF(nCursor < nEndPos, "editeng",
+                "Cursor in the heart of the action?!");
         nCursor -= ( nEndPos-rSttPos );
         pImpEE->ImpInsertText( aSel, pFnd->GetLong() );
         nCursor = nCursor + pFnd->GetLong().Len();


More information about the Libreoffice-commits mailing list