sw/source/filter/ww8/ww8par2.cxx | 45 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+)
New commits: commit ecda845512e1c67c514efbd0b388300ab9ffe8cf Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Sun Jan 2 20:22:24 2022 +0000 Commit: Michael Stahl <michael.st...@allotropia.de> CommitDate: Fri Jan 7 14:22:01 2022 +0100 ofz#43052 crash in WW8TabDesc::MergeCells Change-Id: I4d7acc006458598ad43033fa8e35b2f422d76ff5 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/127770 Tested-by: Jenkins Reviewed-by: Michael Stahl <michael.st...@allotropia.de> diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx index cf07cb7cf038..52ad77c6c6ec 100644 --- a/sw/source/filter/ww8/ww8par2.cxx +++ b/sw/source/filter/ww8/ww8par2.cxx @@ -2791,6 +2791,46 @@ void WW8TabDesc::MoveOutsideTable() *m_pIo->m_pPaM->GetPoint() = *m_xTmpPos->GetPoint(); } +namespace +{ + class SwTableNodeListener final : public SwClient + { + private: + SwModify* m_pModify; + + virtual void SwClientNotify(const SwModify&, const SfxHint& rHint) override + { + if (rHint.GetId() != SfxHintId::SwLegacyModify) + return; + auto pLegacy = static_cast<const sw::LegacyModifyHint*>(&rHint); + if (pLegacy->GetWhich() == RES_OBJECTDYING) + { + m_pModify->Remove(this); + m_pModify = nullptr; + } + } + + public: + SwTableNodeListener(SwModify* pModify) + : m_pModify(pModify) + { + m_pModify->Add(this); + } + + bool WasDeleted() const + { + return !m_pModify; + } + + virtual ~SwTableNodeListener() override + { + if (!m_pModify) + return; + m_pModify->Remove(this); + } + }; +} + void WW8TabDesc::FinishSwTable() { m_pIo->m_xRedlineStack->closeall(*m_pIo->m_pPaM->GetPoint()); @@ -2800,6 +2840,8 @@ void WW8TabDesc::FinishSwTable() std::shared_ptr<SwUnoCursor> xLastAnchorCursor(m_pIo->m_pLastAnchorPos ? m_pIo->m_rDoc.CreateUnoCursor(*m_pIo->m_pLastAnchorPos) : nullptr); m_pIo->m_pLastAnchorPos.reset(); + SwTableNode* pTableNode = m_pTable->GetTableNode(); + SwTableNodeListener aListener(pTableNode); m_pIo->m_xRedlineStack = std::move(mxOldRedlineStack); if (xLastAnchorCursor) @@ -2818,6 +2860,9 @@ void WW8TabDesc::FinishSwTable() m_pIo->m_aInsertedTables.InsertTable(*m_pTableNd, *m_pIo->m_pPaM); + if (aListener.WasDeleted()) + return; + MergeCells(); // if needed group cells together that should be merged