sw/source/filter/html/htmlgrin.cxx | 2 +- sw/source/filter/html/swhtml.cxx | 21 ++++++++++++++++++++- sw/source/filter/html/swhtml.hxx | 11 ++++++++++- 3 files changed, 31 insertions(+), 3 deletions(-)
New commits: commit 1b7a02b4e48ca2d8160443517e03adcd8aaa77d0 Author: Caolán McNamara <caol...@redhat.com> AuthorDate: Mon Oct 26 20:38:03 2020 +0000 Commit: Michael Stahl <michael.st...@cib.de> CommitDate: Wed Oct 28 09:35:49 2020 +0100 ofz#26619 detect if SwFrameFormat deleted during import Change-Id: I5dc778e44dcb670353e83037a5a5d469fa437186 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104853 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caol...@redhat.com> (cherry picked from commit 7ae9e8b6ba35dec2c556f6fac4034cd9bb1111a1) Reviewed-on: https://gerrit.libreoffice.org/c/core/+/104835 Reviewed-by: Michael Stahl <michael.st...@cib.de> diff --git a/sw/source/filter/html/htmlgrin.cxx b/sw/source/filter/html/htmlgrin.cxx index 628ef2704630..11ac33e698d4 100644 --- a/sw/source/filter/html/htmlgrin.cxx +++ b/sw/source/filter/html/htmlgrin.cxx @@ -280,7 +280,7 @@ void SwHTMLParser::RegisterFlyFrame( SwFrameFormat *pFlyFormat ) (RndStdIds::FLY_AT_PARA == pFlyFormat->GetAnchor().GetAnchorId()) && css::text::WrapTextMode_THROUGH == pFlyFormat->GetSurround().GetSurround() ) { - m_aMoveFlyFrames.push_back( pFlyFormat ); + m_aMoveFlyFrames.emplace_back(std::make_unique<SwHTMLFrameFormatListener>(pFlyFormat)); m_aMoveFlyCnts.push_back( m_pPam->GetPoint()->nContent.GetIndex() ); } } diff --git a/sw/source/filter/html/swhtml.cxx b/sw/source/filter/html/swhtml.cxx index 940642a816d4..8503c342c858 100644 --- a/sw/source/filter/html/swhtml.cxx +++ b/sw/source/filter/html/swhtml.cxx @@ -2696,6 +2696,18 @@ SwViewShell *SwHTMLParser::CheckActionViewShell() return m_pActionViewShell; } +SwHTMLFrameFormatListener::SwHTMLFrameFormatListener(SwFrameFormat* pFrameFormat) + : m_pFrameFormat(pFrameFormat) +{ + StartListening(m_pFrameFormat->GetNotifier()); +} + +void SwHTMLFrameFormatListener::Notify(const SfxHint& rHint) +{ + if (rHint.GetId() == SfxHintId::Dying) + m_pFrameFormat = nullptr; +} + void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, std::deque<std::unique_ptr<HTMLAttr>> *pPostIts ) { @@ -2955,7 +2967,14 @@ void SwHTMLParser::SetAttr_( bool bChkEnd, bool bBeforeTable, for( auto n = m_aMoveFlyFrames.size(); n; ) { - SwFrameFormat *pFrameFormat = m_aMoveFlyFrames[ --n ]; + SwFrameFormat *pFrameFormat = m_aMoveFlyFrames[--n]->GetFrameFormat(); + if (!pFrameFormat) + { + SAL_WARN("sw.html", "SwFrameFormat deleted during import"); + m_aMoveFlyFrames.erase( m_aMoveFlyFrames.begin() + n ); + m_aMoveFlyCnts.erase( m_aMoveFlyCnts.begin() + n ); + continue; + } const SwFormatAnchor& rAnchor = pFrameFormat->GetAnchor(); OSL_ENSURE( RndStdIds::FLY_AT_PARA == rAnchor.GetAnchorId(), diff --git a/sw/source/filter/html/swhtml.hxx b/sw/source/filter/html/swhtml.hxx index 59b7db28c467..9fb7dbfce7b5 100644 --- a/sw/source/filter/html/swhtml.hxx +++ b/sw/source/filter/html/swhtml.hxx @@ -331,6 +331,15 @@ namespace o3tl template<> struct typed_flags<HtmlFrameFormatFlags> : is_typed_flags<HtmlFrameFormatFlags, 0x0f> {}; } +class SwHTMLFrameFormatListener : public SvtListener +{ + SwFrameFormat* m_pFrameFormat; +public: + SwHTMLFrameFormatListener(SwFrameFormat* pFrameFormat); + SwFrameFormat* GetFrameFormat() { return m_pFrameFormat; } + virtual void Notify(const SfxHint&) override; +}; + class SwHTMLParser : public SfxHTMLParser, public SvtListener { friend class SectionSaveStruct; @@ -366,7 +375,7 @@ class SwHTMLParser : public SfxHTMLParser, public SvtListener HTMLAttrs m_aParaAttrs; // temporary paragraph attributes std::shared_ptr<HTMLAttrTable> m_xAttrTab; // "open" attributes HTMLAttrContexts m_aContexts;// the current context of attribute/token - std::vector<SwFrameFormat *> m_aMoveFlyFrames;// Fly-Frames, the anchor is moved + std::vector<std::unique_ptr<SwHTMLFrameFormatListener>> m_aMoveFlyFrames;// Fly-Frames, the anchor is moved std::deque<sal_Int32> m_aMoveFlyCnts;// and the Content-Positions //stray SwTableBoxes which need to be deleted to avoid leaking, but hold //onto them until parsing is done _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits