sw/source/uibase/docvw/edtwin.cxx |   18 ++++++------------
 1 file changed, 6 insertions(+), 12 deletions(-)

New commits:
commit 08690fe5c4e5028ccaebc80145be650caf62ea76
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri Mar 4 20:05:03 2022 +0100
Commit:     Thorsten Behrens <thorsten.behr...@allotropia.de>
CommitDate: Sat Mar 12 11:17:45 2022 +0100

    sw_redlinehide: fix crashes in SwEditWin Surrounding functions
    
    These foolish functions write into the shell cursor!
    
    But the shell cursor's node isn't necessarily the same as before with
    merged paragraphs, so could crash with out of bounds indexes.
    
    Better use Push()/Pop().
    
    Change-Id: I4fd0e2aa915b6c5448772a2c766848607bbf5aaa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131041
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>
    (cherry picked from commit aac9bd235e65b27faf63e64bba3ecd94837381d6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131127
    Reviewed-by: Thorsten Behrens <thorsten.behr...@allotropia.de>

diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index 59af6a581a6b..31f4c69e162e 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -6435,9 +6435,7 @@ OUString SwEditWin::GetSurroundingText() const
     {
         bool bUnLockView = !rSh.IsViewLocked();
         rSh.LockView(true);
-
-        SwPosition *pPos = rSh.GetCursor()->GetPoint();
-        const sal_Int32 nPos = pPos->nContent.GetIndex();
+        rSh.Push();
 
         // get the sentence around the cursor
         rSh.HideCursor();
@@ -6446,8 +6444,7 @@ OUString SwEditWin::GetSurroundingText() const
         rSh.GoEndSentence();
         rSh.GetSelectedText( sReturn, ParaBreakType::ToOnlyCR  );
 
-        pPos->nContent = nPos;
-        rSh.ClearMark();
+        rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
         rSh.HideCursor();
 
         if (bUnLockView)
@@ -6479,13 +6476,13 @@ Selection SwEditWin::GetSurroundingTextSelection() const
         // around the visible cursor.
         SwPosition *pPos = rSh.GetCursor()->GetPoint();
         const sal_Int32 nPos = pPos->nContent.GetIndex();
+        rSh.Push();
 
         rSh.HideCursor();
         rSh.GoStartSentence();
         const sal_Int32 nStartPos = 
rSh.GetCursor()->GetPoint()->nContent.GetIndex();
 
-        pPos->nContent = nPos;
-        rSh.ClearMark();
+        rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
         rSh.ShowCursor();
 
         if (bUnLockView)
@@ -6507,14 +6504,11 @@ bool SwEditWin::DeleteSurroundingText(const Selection& 
rSelection)
 
     // rSelection is relative to the start of the sentence, so find that and
     // adjust the range by it
-    SwPosition *pPos = rSh.GetCursor()->GetPoint();
-    const sal_Int32 nPos = pPos->nContent.GetIndex();
-
+    rSh.Push();
     rSh.HideCursor();
     rSh.GoStartSentence();
     const sal_Int32 nStartPos = 
rSh.GetCursor()->GetPoint()->nContent.GetIndex();
-    pPos->nContent = nPos;
-    rSh.ClearMark();
+    rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
     rSh.ShowCursor();
 
     if (rSh.SelectText(nStartPos + rSelection.Min(), nStartPos + 
rSelection.Max()))

Reply via email to