sw/source/core/frmedt/fecopy.cxx |   13 +++++++------
 1 file changed, 7 insertions(+), 6 deletions(-)

New commits:
commit 1b8c42f8b007d690a85676f260b28b44639fc79a
Author:     Michael Stahl <michael.st...@allotropia.de>
AuthorDate: Fri May 20 16:01:57 2022 +0200
Commit:     Michael Stahl <michael.st...@allotropia.de>
CommitDate: Mon May 23 10:53:20 2022 +0200

    sw: avoid ~SwIndexReg() assert in SwFEShell::PastePages()
    
    Change-Id: I5337dc8568255a778d29b676a39c99f72c42486b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134693
    Tested-by: Jenkins
    Reviewed-by: Michael Stahl <michael.st...@allotropia.de>

diff --git a/sw/source/core/frmedt/fecopy.cxx b/sw/source/core/frmedt/fecopy.cxx
index 6e28597024c9..f1db6d946f45 100644
--- a/sw/source/core/frmedt/fecopy.cxx
+++ b/sw/source/core/frmedt/fecopy.cxx
@@ -1133,7 +1133,7 @@ void SwFEShell::PastePages( SwFEShell& rToFill, 
sal_uInt16 nStartPage, sal_uInt1
         return;
     }
     MovePage( GetThisFrame, GetFirstSub );
-    SwPaM aCpyPam( *GetCursor()->GetPoint() );
+    ::std::optional<SwPaM> oSourcePam( *GetCursor()->GetPoint() );
     OUString sStartingPageDesc = GetPageDesc( GetCurPageDesc()).GetName();
     SwPageDesc* pDesc = rToFill.FindPageDescByName( sStartingPageDesc, true );
     if( pDesc )
@@ -1145,7 +1145,7 @@ void SwFEShell::PastePages( SwFEShell& rToFill, 
sal_uInt16 nStartPage, sal_uInt1
         return;
     }
     //if the page starts with a table a paragraph has to be inserted before
-    SwNode* pTableNode = aCpyPam.GetNode().FindTableNode();
+    SwNode *const pTableNode = oSourcePam->GetNode().FindTableNode();
     if(pTableNode)
     {
         //insert a paragraph
@@ -1155,22 +1155,23 @@ void SwFEShell::PastePages( SwFEShell& rToFill, 
sal_uInt16 nStartPage, sal_uInt1
         if(GetDoc()->getIDocumentContentOperations().AppendTextNode( aBefore ))
         {
             SwPaM aTmp(aBefore);
-            aCpyPam = aTmp;
+            *oSourcePam = aTmp;
         }
         EndUndo(SwUndoId::INSERT);
     }
 
     MovePage( GetThisFrame, GetLastSub );
-    aCpyPam.SetMark();
-    *aCpyPam.GetMark() = *GetCursor()->GetPoint();
+    oSourcePam->SetMark();
+    *oSourcePam->GetMark() = *GetCursor()->GetPoint();
 
     CurrShell aCurr( this );
 
     StartAllAction();
     GetDoc()->getIDocumentFieldsAccess().LockExpFields();
-    SetSelection(aCpyPam);
+    SetSelection(*oSourcePam);
     // copy the text of the selection
     SwEditShell::Copy(rToFill);
+    oSourcePam.reset(); // delete it because Undo will remove its node!
 
     if(pTableNode)
     {

Reply via email to