sw/source/core/inc/rolbck.hxx | 4 ++-- sw/source/core/undo/rolbck.cxx | 12 ++++++++---- sw/source/core/undo/undobj.cxx | 10 +++++----- sw/source/core/undo/untbl.cxx | 2 +- 4 files changed, 16 insertions(+), 12 deletions(-)
New commits: commit 783ff7aacf72d907b43b26926131966b199ebb90 Author: Michael Stahl <michael.st...@cib.de> AuthorDate: Tue Nov 19 10:54:57 2019 +0100 Commit: Miklos Vajna <vmik...@collabora.com> CommitDate: Thu Feb 20 18:52:08 2020 +0100 sw: fix invalid downcast of SwDrawFrameFormat in DelContentIndex() failure in UITest_writer_tests6: sw/source/core/undo/undobj.cxx:1021:47: runtime error: downcast of address 0x61300019d3c0 which does not point to an object of type 'SwFlyFrameFormat' 0x61300019d3c0:m note: object is of type 'SwDrawFrameFormat' a2 01 80 19 50 ac d1 9e 14 7f 00 00 00 af 19 00 30 61 00 00 e8 4f 0b 00 b0 61 00 00 40 dd 40 00 ^~~~~~~~~~~~~~~~~~~~~~~ vptr for 'SwDrawFrameFormat' in SwUndoSaveContent::DelContentIndex(SwPosition const&, SwPosition const&, DelContentType) at sw/source/core/undo/undobj.cxx:1021:47 (instdir/program/../program/libswlo.so +0xf8e5833) Also lose the ridiculous overloading across derived classes. (cherry picked from commit 8f7274682661baec4c9b160ee2165972bbfa9881) Conflicts: sw/source/core/undo/undobj.cxx Change-Id: I19439d0d511c5f8c36b00d8dd02c31f802a44e00 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/89097 Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoff...@gmail.com> Reviewed-by: Miklos Vajna <vmik...@collabora.com> diff --git a/sw/source/core/inc/rolbck.hxx b/sw/source/core/inc/rolbck.hxx index 2feec7e6d973..619b0577c613 100644 --- a/sw/source/core/inc/rolbck.hxx +++ b/sw/source/core/inc/rolbck.hxx @@ -361,8 +361,8 @@ public: void Add( SwTextAttr* pTextHt, sal_uLong nNodeIdx, bool bNewAttr ); void Add( SwFormatColl*, sal_uLong nNodeIdx, SwNodeType nWhichNd ); void Add( const ::sw::mark::IMark&, bool bSavePos, bool bSaveOtherPos ); - void Add( SwFrameFormat& rFormat ); - void Add( SwFlyFrameFormat&, sal_uInt16& rSetPos ); + void AddChangeFlyAnchor( SwFrameFormat& rFormat ); + void AddDeleteFly( SwFrameFormat&, sal_uInt16& rSetPos ); void Add( const SwTextFootnote& ); void Add( const SfxItemSet & rSet, const SwCharFormat & rCharFormat); diff --git a/sw/source/core/undo/rolbck.cxx b/sw/source/core/undo/rolbck.cxx index 495ce724032d..973054c47664 100644 --- a/sw/source/core/undo/rolbck.cxx +++ b/sw/source/core/undo/rolbck.cxx @@ -1067,18 +1067,21 @@ void SwHistory::Add(const ::sw::mark::IMark& rBkmk, bool bSavePos, bool bSaveOth m_SwpHstry.push_back( std::move(pHt) ); } -void SwHistory::Add( SwFrameFormat& rFormat ) +void SwHistory::AddChangeFlyAnchor(SwFrameFormat& rFormat) { std::unique_ptr<SwHistoryHint> pHt(new SwHistoryChangeFlyAnchor( rFormat )); m_SwpHstry.push_back( std::move(pHt) ); } -void SwHistory::Add( SwFlyFrameFormat& rFormat, sal_uInt16& rSetPos ) +void SwHistory::AddDeleteFly(SwFrameFormat& rFormat, sal_uInt16& rSetPos) { OSL_ENSURE( !m_nEndDiff, "History was not deleted after REDO" ); const sal_uInt16 nWh = rFormat.Which(); - if( RES_FLYFRMFMT == nWh || RES_DRAWFRMFMT == nWh ) + (void) nWh; + // only Flys! + assert((RES_FLYFRMFMT == nWh && dynamic_cast<SwFlyFrameFormat*>(&rFormat)) + || (RES_DRAWFRMFMT == nWh && dynamic_cast<SwDrawFrameFormat*>(&rFormat))); { std::unique_ptr<SwHistoryHint> pHint(new SwHistoryTextFlyCnt( &rFormat )); m_SwpHstry.push_back( std::move(pHint) ); @@ -1087,10 +1090,11 @@ void SwHistory::Add( SwFlyFrameFormat& rFormat, sal_uInt16& rSetPos ) if( SfxItemState::SET == rFormat.GetItemState( RES_CHAIN, false, reinterpret_cast<const SfxPoolItem**>(&pChainItem) )) { + assert(RES_FLYFRMFMT == nWh); // not supported on SdrObjects if( pChainItem->GetNext() || pChainItem->GetPrev() ) { std::unique_ptr<SwHistoryHint> pHt( - new SwHistoryChangeFlyChain( rFormat, *pChainItem )); + new SwHistoryChangeFlyChain(static_cast<SwFlyFrameFormat&>(rFormat), *pChainItem)); m_SwpHstry.insert( m_SwpHstry.begin() + rSetPos++, std::move(pHt) ); if ( pChainItem->GetNext() ) { diff --git a/sw/source/core/undo/undobj.cxx b/sw/source/core/undo/undobj.cxx index 452091c548f8..dcbe3a4a04cc 100644 --- a/sw/source/core/undo/undobj.cxx +++ b/sw/source/core/undo/undobj.cxx @@ -992,7 +992,7 @@ void SwUndoSaveContent::DelContentIndex( const SwPosition& rMark, // Do not try to move the anchor to a table! && rMark.nNode.GetNode().IsTextNode()) { - pHistory->Add( *pFormat ); + pHistory->AddChangeFlyAnchor(*pFormat); SwFormatAnchor aAnch( *pAnchor ); SwPosition aPos( rMark.nNode ); aAnch.SetAnchor( &aPos ); @@ -1000,7 +1000,7 @@ void SwUndoSaveContent::DelContentIndex( const SwPosition& rMark, } else { - pHistory->Add( *static_cast<SwFlyFrameFormat *>(pFormat), nChainInsPos ); + pHistory->AddDeleteFly(*pFormat, nChainInsPos ); // reset n so that no Format is skipped n = n >= rSpzArr.size() ? rSpzArr.size() : n+1; @@ -1018,7 +1018,7 @@ void SwUndoSaveContent::DelContentIndex( const SwPosition& rMark, if (IsDestroyFrameAnchoredAtChar( *pAPos, *pStt, *pEnd, nDelContentType)) { - pHistory->Add( *static_cast<SwFlyFrameFormat *>(pFormat), nChainInsPos ); + pHistory->AddDeleteFly(*pFormat, nChainInsPos); n = n >= rSpzArr.size() ? rSpzArr.size() : n+1; } else if (!((DelContentType::CheckNoCntnt | @@ -1032,7 +1032,7 @@ void SwUndoSaveContent::DelContentIndex( const SwPosition& rMark, // Do not try to move the anchor to a table! if( rMark.nNode.GetNode().GetTextNode() ) { - pHistory->Add( *pFormat ); + pHistory->AddChangeFlyAnchor(*pFormat); SwFormatAnchor aAnch( *pAnchor ); aAnch.SetAnchor( &rMark ); pFormat->SetFormatAttr( aAnch ); @@ -1049,7 +1049,7 @@ void SwUndoSaveContent::DelContentIndex( const SwPosition& rMark, if( !pHistory ) pHistory.reset( new SwHistory ); - pHistory->Add( *static_cast<SwFlyFrameFormat *>(pFormat), nChainInsPos ); + pHistory->AddDeleteFly(*pFormat, nChainInsPos); // reset n so that no Format is skipped n = n >= rSpzArr.size() ? rSpzArr.size() : n+1; diff --git a/sw/source/core/undo/untbl.cxx b/sw/source/core/undo/untbl.cxx index 0640fd478022..5f815d4910d6 100644 --- a/sw/source/core/undo/untbl.cxx +++ b/sw/source/core/undo/untbl.cxx @@ -423,7 +423,7 @@ SwUndoTableToText::SwUndoTableToText( const SwTable& rTable, sal_Unicode cCh ) nTableStt <= pAPos->nNode.GetIndex() && pAPos->nNode.GetIndex() < nTableEnd ) { - pHistory->Add( *pFormat ); + pHistory->AddChangeFlyAnchor(*pFormat); } } _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits