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

New commits:
commit 846ff2d3723c120ad8972b6757a180e8cd627007
Author:     Michael Stahl <[email protected]>
AuthorDate: Fri Mar 4 20:05:03 2022 +0100
Commit:     Thorsten Behrens <[email protected]>
CommitDate: Wed Mar 16 02:08:07 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().
    
    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/+/131127
    Reviewed-by: Thorsten Behrens <[email protected]>
    (cherry picked from commit 08690fe5c4e5028ccaebc80145be650caf62ea76)
    
    Change-Id: I4fd0e2aa915b6c5448772a2c766848607bbf5aaa
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/131624
    Tested-by: Thorsten Behrens <[email protected]>
    Reviewed-by: Thorsten Behrens <[email protected]>

diff --git a/sw/source/uibase/docvw/edtwin.cxx 
b/sw/source/uibase/docvw/edtwin.cxx
index 80c00954fa0e..0887baca08ed 100644
--- a/sw/source/uibase/docvw/edtwin.cxx
+++ b/sw/source/uibase/docvw/edtwin.cxx
@@ -6285,8 +6285,7 @@ OUString SwEditWin::GetSurroundingText() const
         rSh.GetSelectedText( sReturn, ParaBreakType::ToOnlyCR  );
     else if( !rSh.HasSelection() )
     {
-        SwPosition *pPos = rSh.GetCursor()->GetPoint();
-        const sal_Int32 nPos = pPos->nContent.GetIndex();
+        rSh.Push();
 
         // get the sentence around the cursor
         rSh.HideCursor();
@@ -6295,8 +6294,7 @@ OUString SwEditWin::GetSurroundingText() const
         rSh.GoEndSentence();
         rSh.GetSelectedText( sReturn, ParaBreakType::ToOnlyCR  );
 
-        pPos->nContent = nPos;
-        rSh.ClearMark();
+        rSh.Pop(SwCursorShell::PopMode::DeleteCurrent);
         rSh.HideCursor();
     }
 
@@ -6318,13 +6316,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();
 
         return Selection( nPos - nStartPos, nPos - nStartPos );

Reply via email to