sc/source/ui/inc/undobase.hxx  |    2 +-
 sc/source/ui/undo/undobase.cxx |    5 -----
 sc/source/ui/undo/undoblk.cxx  |    7 +++----
 3 files changed, 4 insertions(+), 10 deletions(-)

New commits:
commit d82fffff53e824b571fd7b7c65c51324ddf9549e
Author:     Caolán McNamara <caolan.mcnam...@collabora.com>
AuthorDate: Wed Jul 17 14:23:33 2024 +0100
Commit:     Caolán McNamara <caolan.mcnam...@collabora.com>
CommitDate: Wed Jul 17 20:52:22 2024 +0200

    cid#1555302 Different smart pointers managing same raw pointer
    
    ScUndoWrapper::ForgetWrappedUndo resets the std::unique_ptr
    and deletes the owned pointer, that's not what we want to happen here.
    
    looks to have gone wrong in:
    
    commit 9767537e22e178eb23872de138ea70e57c1a6725
    AuthorDate: Tue Jan 17 10:11:31 2017 +0200
    
        new loplugin: useuniqueptr: sc part 2
    
    Change-Id: Ib4a7d615bc2e354f76b044b5b5e5d2f17dbebf0f
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/170632
    Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com>
    Tested-by: Jenkins
    Reviewed-by: Noel Grandin <noel.gran...@collabora.co.uk>

diff --git a/sc/source/ui/inc/undobase.hxx b/sc/source/ui/inc/undobase.hxx
index f7eca9ba8777..4ca471d5f1bc 100644
--- a/sc/source/ui/inc/undobase.hxx
+++ b/sc/source/ui/inc/undobase.hxx
@@ -167,7 +167,7 @@ public:
     virtual                 ~ScUndoWrapper() override;
 
     SfxUndoAction*          GetWrappedUndo()        { return 
pWrappedUndo.get(); }
-    void                    ForgetWrappedUndo();
+    std::unique_ptr<SfxUndoAction> ReleaseWrappedUndo() { return 
std::move(pWrappedUndo); }
 
     virtual void            Undo() override;
     virtual void            Redo() override;
diff --git a/sc/source/ui/undo/undobase.cxx b/sc/source/ui/undo/undobase.cxx
index 9bcd5349f67a..f939351fa19d 100644
--- a/sc/source/ui/undo/undobase.cxx
+++ b/sc/source/ui/undo/undobase.cxx
@@ -570,11 +570,6 @@ ScUndoWrapper::~ScUndoWrapper()
 {
 }
 
-void ScUndoWrapper::ForgetWrappedUndo()
-{
-    pWrappedUndo = nullptr;    // don't delete in dtor - pointer must be 
stored outside
-}
-
 OUString ScUndoWrapper::GetComment() const
 {
     if (pWrappedUndo)
diff --git a/sc/source/ui/undo/undoblk.cxx b/sc/source/ui/undo/undoblk.cxx
index 46c10bfe6f5d..cd96fa833f21 100644
--- a/sc/source/ui/undo/undoblk.cxx
+++ b/sc/source/ui/undo/undoblk.cxx
@@ -109,14 +109,13 @@ bool ScUndoInsertCells::Merge( SfxUndoAction* pNextAction 
)
     if ( bPartOfPaste )
         if ( auto pWrapper = dynamic_cast<ScUndoWrapper*>( pNextAction) )
         {
-            SfxUndoAction* pWrappedAction = pWrapper->GetWrappedUndo();
-            if ( dynamic_cast<const ScUndoPaste*>( pWrappedAction) )
+            if (dynamic_cast<const ScUndoPaste*>(pWrapper->GetWrappedUndo()))
             {
                 //  Store paste action if this is part of paste with inserting 
cells.
                 //  A list action isn't used because Repeat wouldn't work 
(insert wrong cells).
 
-                pPasteUndo.reset( pWrappedAction );
-                pWrapper->ForgetWrappedUndo();      // pWrapper is deleted by 
UndoManager
+                // Pass ownership of the wrapped SfxUndoAction* to pPasteUndO
+                pPasteUndo = pWrapper->ReleaseWrappedUndo();
                 return true;
             }
         }

Reply via email to