summaryrefslogtreecommitdiff
path: root/sc/source/ui
diff options
context:
space:
mode:
authorCaolán McNamara <caolan.mcnamara@collabora.com>2024-07-17 14:23:33 +0100
committerCaolán McNamara <caolan.mcnamara@collabora.com>2024-07-17 20:52:22 +0200
commitd82fffff53e824b571fd7b7c65c51324ddf9549e (patch)
treeabf1552ea96c9a8999c1788b4bcf4e18645ec901 /sc/source/ui
parent5bc5c936e18ccfe20f219c8bf92bf6652d965269 (diff)
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.mcnamara@collabora.com> Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sc/source/ui')
-rw-r--r--sc/source/ui/inc/undobase.hxx2
-rw-r--r--sc/source/ui/undo/undobase.cxx5
-rw-r--r--sc/source/ui/undo/undoblk.cxx7
3 files changed, 4 insertions, 10 deletions
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;
}
}