Hi All,

This patch will fix fdo#40831 "Writer will crash when searching text with using 
regular expressions".
Please review my attached patch.

Bug URL: https://bugs.freedesktop.org/show_bug.cgi?id=40831

I reproduced this bug on LibO 3.4 and 3.5.
This bug occurs when a row or column containing cursor position was removed by 
substitution. 
This patch is to skip the process of returning the position of the cursor,
when the row or column containing cursor position is removed.


My patch is being submitted under LGPLv3+/MPL.

Regards,
Tomofumi Yagi.  


diff --git a/sw/source/core/crsr/swcrsr.cxx b/sw/source/core/crsr/swcrsr.cxx
index c27d8f7..fd6c782 100644
--- a/sw/source/core/crsr/swcrsr.cxx
+++ b/sw/source/core/crsr/swcrsr.cxx
@@ -2091,10 +2091,22 @@ sal_Bool SwCursor::MoveSection( SwWhichSection 
fnWhichSect,
 
 void SwCursor::RestoreSavePos()
 {
-    if( pSavePos )
+    // fdo#40831 if you delete the row or column containing pSavePos,
+    // Writer will crash. Work around this.
+    sal_uLong uNodeCount = GetPoint()->nNode.GetNodes().Count();
+    if( pSavePos && pSavePos->nNode <= uNodeCount )
     {
         GetPoint()->nNode = pSavePos->nNode;
-        GetPoint()->nContent.Assign( GetCntntNode(), pSavePos->nCntnt );
+
+        xub_StrLen nIdx = 0;
+        if ( GetCntntNode() ) 
+            if ( pSavePos->nCntnt <= GetCntntNode()->Len() ) 
+                nIdx = pSavePos->nCntnt;
+            else 
+                nIdx = GetCntntNode()->Len(); 
+        else 
+            nIdx = GetPoint()->nContent.GetIndex(); // Probably, nIdx = 0
+        GetPoint()->nContent.Assign( GetCntntNode(), nIdx );
     }
 }
 
_______________________________________________
LibreOffice mailing list
LibreOffice@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice

Reply via email to