sw/source/core/inc/txtfrm.hxx | 3 +-- sw/source/core/text/frmcrsr.cxx | 2 +- sw/source/core/text/txtcache.cxx | 24 ++++++++++-------------- sw/source/core/text/txtcache.hxx | 19 +++++++++++-------- sw/source/core/text/txtfrm.cxx | 21 ++++++++++++--------- sw/source/core/text/txtftn.cxx | 2 +- 6 files changed, 36 insertions(+), 35 deletions(-)
New commits: commit 3998282717db05cb7c37f8b19d2bf6d69e2e907f Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Wed Aug 20 09:37:03 2025 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed Aug 20 16:28:46 2025 +0200 Revert "cid#1660822 Different smart pointers managing same raw pointer" This reverts commit fae1a210dcc817862045e7db6edf9eabe60d7557 in the stable branch. Change-Id: Ic222d24a03a289a83cddbeb0008dcc321b9de33e Reviewed-on: https://gerrit.libreoffice.org/c/core/+/189954 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sw/source/core/inc/txtfrm.hxx b/sw/source/core/inc/txtfrm.hxx index bb3a8bc5015c..2190dd0f34ff 100644 --- a/sw/source/core/inc/txtfrm.hxx +++ b/sw/source/core/inc/txtfrm.hxx @@ -300,8 +300,7 @@ class SW_DLLPUBLIC SwTextFrame final : public SwContentFrame bool GetDropRect_( SwRect &rRect ) const; - // returns the old SwParaPortion, if present - std::unique_ptr<SwParaPortion> SetPara(std::unique_ptr<SwParaPortion> xNew); + void SetPara(SwParaPortion *pNew, bool bDelete); bool IsFootnoteNumFrame_() const; diff --git a/sw/source/core/text/frmcrsr.cxx b/sw/source/core/text/frmcrsr.cxx index 28a5db42b606..2324e99daccf 100644 --- a/sw/source/core/text/frmcrsr.cxx +++ b/sw/source/core/text/frmcrsr.cxx @@ -129,7 +129,7 @@ bool sw_ChangeOffset(SwTextFrame* pFrame, TextFrameIndex nNew) nNew = TextFrameIndex(0); } pFrame->SetOffset( nNew ); - pFrame->SetPara(nullptr); + pFrame->SetPara(nullptr, true); pFrame->GetFormatted(); if( pFrame->getFrameArea().HasArea() ) pFrame->getRootFrame()->GetCurrShell()->InvalidateWindows( pFrame->getFrameArea() ); diff --git a/sw/source/core/text/txtcache.cxx b/sw/source/core/text/txtcache.cxx index 8a7470030f29..188fa7bec697 100644 --- a/sw/source/core/text/txtcache.cxx +++ b/sw/source/core/text/txtcache.cxx @@ -25,9 +25,9 @@ #include <osl/diagnose.h> #include <view.hxx> -SwTextLine::SwTextLine(SwTextFrame const *pFrame, std::unique_ptr<SwParaPortion> xNew) - : SwCacheObj(static_cast<void const *>(pFrame)) - , m_xLine(std::move(xNew) ) +SwTextLine::SwTextLine( SwTextFrame const *pFrame, std::unique_ptr<SwParaPortion> pNew ) : + SwCacheObj( static_cast<void const *>(pFrame) ), + m_pLine( std::move(pNew) ) { } @@ -58,7 +58,7 @@ SwParaPortion *SwTextLineAccess::GetPara() const_cast<SwTextFrame *>(static_cast<SwTextFrame const *>(m_pOwner))->SetCacheIdx( pRet->GetCachePos() ); } if ( !pRet->GetPara() ) - pRet->SetPara(std::make_unique<SwParaPortion>()); + pRet->SetPara( new SwParaPortion, true/*bDelete*/ ); return pRet->GetPara(); } @@ -110,7 +110,7 @@ void SwTextFrame::ClearPara() Get( this, GetCacheIdx(), false )); if ( pTextLine ) { - pTextLine->SetPara(nullptr); + pTextLine->SetPara( nullptr, true/*bDelete*/ ); } else mnCacheIndex = USHRT_MAX; @@ -126,10 +126,8 @@ void SwTextFrame::RemoveFromCache() } } -std::unique_ptr<SwParaPortion> SwTextFrame::SetPara(std::unique_ptr<SwParaPortion> xNew) +void SwTextFrame::SetPara( SwParaPortion *pNew, bool bDelete ) { - std::unique_ptr<SwParaPortion> xOld; - if ( GetCacheIdx() != USHRT_MAX ) { // Only change the information, the CacheObj stays there @@ -137,17 +135,17 @@ std::unique_ptr<SwParaPortion> SwTextFrame::SetPara(std::unique_ptr<SwParaPortio Get( this, GetCacheIdx(), false )); if ( pTextLine ) { - xOld = pTextLine->SetPara(std::move(xNew)); + pTextLine->SetPara( pNew, bDelete ); } else { - OSL_ENSURE( !xNew, "+SetPara: Losing SwParaPortion" ); + OSL_ENSURE( !pNew, "+SetPara: Losing SwParaPortion" ); mnCacheIndex = USHRT_MAX; } } - else if (xNew) + else if ( pNew ) { // Insert a new one - SwTextLine *pTextLine = new SwTextLine(this, std::move(xNew)); + SwTextLine *pTextLine = new SwTextLine( this, std::unique_ptr<SwParaPortion>(pNew) ); if (SwTextFrame::GetTextCache()->Insert(pTextLine, false)) mnCacheIndex = pTextLine->GetCachePos(); else @@ -155,8 +153,6 @@ std::unique_ptr<SwParaPortion> SwTextFrame::SetPara(std::unique_ptr<SwParaPortio OSL_FAIL( "+SetPara: InsertCache failed." ); } } - - return xOld; } /** Prevent the SwParaPortions of the *visible* paragraphs from being deleted; diff --git a/sw/source/core/text/txtcache.hxx b/sw/source/core/text/txtcache.hxx index 68f907de4597..ee18f14c3b0c 100644 --- a/sw/source/core/text/txtcache.hxx +++ b/sw/source/core/text/txtcache.hxx @@ -27,22 +27,25 @@ class SwTextFrame; class SwTextLine : public SwCacheObj { - std::unique_ptr<SwParaPortion> m_xLine; + std::unique_ptr<SwParaPortion> m_pLine; virtual void UpdateCachePos() override; public: - SwTextLine(SwTextFrame const* pFrame, std::unique_ptr<SwParaPortion> xNew = nullptr); + SwTextLine(SwTextFrame const* pFrame, std::unique_ptr<SwParaPortion> pNew = nullptr); virtual ~SwTextLine() override; - SwParaPortion* GetPara() { return m_xLine.get(); } - const SwParaPortion* GetPara() const { return m_xLine.get(); } + SwParaPortion* GetPara() { return m_pLine.get(); } + const SwParaPortion* GetPara() const { return m_pLine.get(); } - std::unique_ptr<SwParaPortion> SetPara(std::unique_ptr<SwParaPortion> xNew) + void SetPara(SwParaPortion* pNew, bool bDelete) { - std::unique_ptr<SwParaPortion> xOld = std::move(m_xLine); - m_xLine = std::move(xNew); - return xOld; + if (!bDelete) + { + // coverity[leaked_storage] - intentional, ownership transferred + (void)m_pLine.release(); + } + m_pLine.reset(pNew); } }; diff --git a/sw/source/core/text/txtfrm.cxx b/sw/source/core/text/txtfrm.cxx index d19f8f5a4c38..6e6687faabc8 100644 --- a/sw/source/core/text/txtfrm.cxx +++ b/sw/source/core/text/txtfrm.cxx @@ -3387,7 +3387,7 @@ bool SwTextFrame::Prepare( const PrepareHint ePrep, const void* pVoid, class SwTestFormat { SwTextFrame *pFrame; - std::unique_ptr<SwParaPortion> xOldPara; + SwParaPortion *pOldPara; SwRect aOldFrame, aOldPrt; public: SwTestFormat( SwTextFrame* pTextFrame, const SwFrame* pPrv, SwTwips nMaxHeight ); @@ -3439,7 +3439,8 @@ SwTestFormat::SwTestFormat( SwTextFrame* pTextFrame, const SwFrame* pPre, SwTwip aRectFnSet.SetWidth( aPrt, aRectFnSet.GetWidth(pFrame->getFrameArea()) - ( rAttrs.CalcLeft( pFrame ) + rAttrs.CalcRight( pFrame ) ) ); } - xOldPara = pFrame->SetPara(std::make_unique<SwParaPortion>()); + pOldPara = pFrame->HasPara() ? pFrame->GetPara() : nullptr; + pFrame->SetPara( new SwParaPortion(), false ); OSL_ENSURE( ! pFrame->IsSwapped(), "A frame is swapped before Format_" ); if ( pFrame->IsVertical() ) @@ -3468,7 +3469,7 @@ SwTestFormat::~SwTestFormat() aPrt.setSwRect(aOldPrt); } - pFrame->SetPara(std::move(xOldPara)); + pFrame->SetPara(pOldPara, true); } bool SwTextFrame::TestFormat( const SwFrame* pPrv, SwTwips &rMaxHeight, bool &bSplit ) @@ -3665,8 +3666,9 @@ SwTwips SwTextFrame::CalcFitToContent() if ( IsLocked() ) return getFramePrintArea().Width(); - //Swap old para for a dummy - std::unique_ptr<SwParaPortion> xOldPara = SetPara(std::make_unique<SwParaPortion>()); + SwParaPortion* pOldPara = GetPara(); + SwParaPortion *pDummy = new SwParaPortion(); + SetPara( pDummy, false ); const SwPageFrame* pPage = FindPageFrame(); const Point aOldFramePos = getFrameArea().Pos(); @@ -3719,8 +3721,7 @@ SwTwips SwTextFrame::CalcFitToContent() aPrt.Width( nOldPrtWidth ); } - //restore original para - SetPara(std::move(xOldPara)); + SetPara(pOldPara, true); // tdf#164932 handle numbering list offset const SwTextNode* pTextNode( GetTextNodeForParaProps() ); @@ -3771,7 +3772,9 @@ void SwTextFrame::CalcAdditionalFirstLineOffset() return; // keep current paragraph portion and apply dummy paragraph portion - std::unique_ptr<SwParaPortion> xOldPara = SetPara(std::make_unique<SwParaPortion>()); + SwParaPortion* pOldPara = GetPara(); + SwParaPortion *pDummy = new SwParaPortion(); + SetPara( pDummy, false ); // lock paragraph TextFrameLockGuard aLock( this ); @@ -3811,7 +3814,7 @@ void SwTextFrame::CalcAdditionalFirstLineOffset() } // restore paragraph portion - SetPara(std::move(xOldPara)); + SetPara(pOldPara, true); } /** diff --git a/sw/source/core/text/txtftn.cxx b/sw/source/core/text/txtftn.cxx index 8a6c1613a774..a941e5eca2d8 100644 --- a/sw/source/core/text/txtftn.cxx +++ b/sw/source/core/text/txtftn.cxx @@ -166,7 +166,7 @@ bool SwTextFrame::CalcPrepFootnoteAdjust() SwTextFormatInfo aInf( getRootFrame()->GetCurrShell()->GetOut(), this ); SwTextFormatter aLine( this, &aInf ); aLine.TruncLines(); - SetPara(nullptr); // May be deleted! + SetPara(nullptr, true); // May be deleted! ResetPreps(); return false; }