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

New commits:
commit 16bc5f2c9db7a414ec88adaccebd70b678d9a405
Author:     Michael Stahl <[email protected]>
AuthorDate: Fri Mar 4 20:05:03 2022 +0100
Commit:     Thorsten Behrens <[email protected]>
CommitDate: Sat Mar 12 11:17:18 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 <[email protected]>
    (cherry picked from commit aac9bd235e65b27faf63e64bba3ecd94837381d6)
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131128
    Reviewed-by: Thorsten Behrens <[email protected]>

diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index d6b30438853a..b21405a7c715 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -6421,9 +6421,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();
@@ -6432,8 +6430,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)
@@ -6465,13 +6462,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)
@@ -6493,14 +6490,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