From d4b79c0d8d4101d92fa3484dd8db2369bc213a46 Mon Sep 17 00:00:00 2001 From: Caolán McNamara Date: Mon, 1 Nov 2021 17:34:23 +0000 Subject: ofz#40593 remove Objects from m_xResizeDrawObjects if deleted during parse MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124563 Tested-by: Jenkins Reviewed-by: Caolán McNamara (cherry picked from commit 2f01faaf88b6d172d7293f0c9e2a061d99b8ceb5) fix misplaced line Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124630 Tested-by: Jenkins Reviewed-by: Caolán McNamara (cherry picked from commit 4ed359093c991291216c39cffe14a60e607ec551) Change-Id: I11fa665175ef067a36f4822676c02d4df1e1e250 --- sw/qa/core/data/html/pass/ofz40593-1.html | Bin 0 -> 5192 bytes sw/source/filter/html/htmltab.cxx | 33 +++++++++++++++++++++++++++--- 2 files changed, 30 insertions(+), 3 deletions(-) create mode 100644 sw/qa/core/data/html/pass/ofz40593-1.html diff --git a/sw/qa/core/data/html/pass/ofz40593-1.html b/sw/qa/core/data/html/pass/ofz40593-1.html new file mode 100644 index 000000000000..43510d5d00b2 Binary files /dev/null and b/sw/qa/core/data/html/pass/ofz40593-1.html differ diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx index 9e7230dc7b35..2a78a258fb22 100644 --- a/sw/source/filter/html/htmltab.cxx +++ b/sw/source/filter/html/htmltab.cxx @@ -35,6 +35,8 @@ #include #include #include +#include +#include #include #include @@ -369,7 +371,7 @@ typedef std::vector HTMLTableColumns; typedef std::vector SdrObjects; -class HTMLTable +class HTMLTable : public sdr::ObjectUser { OUString m_aId; OUString m_aStyle; @@ -517,6 +519,8 @@ private: sal_uInt16 GetBorderWidth( const SvxBorderLine& rBLine, bool bWithDistance=false ) const; + virtual void ObjectInDestruction(const SdrObject& rObject) override; + public: bool m_bFirstCell; // is there a cell created already? @@ -526,7 +530,7 @@ public: bool bHasToFly, const HTMLTableOptions& rOptions); - ~HTMLTable(); + virtual ~HTMLTable(); // Identifying of a cell const HTMLTableCell& GetCell(sal_uInt16 nRow, sal_uInt16 nCell) const; @@ -1055,11 +1059,33 @@ void SwHTMLParser::DeregisterHTMLTable(HTMLTable* pOld) m_aTables.erase(std::remove(m_aTables.begin(), m_aTables.end(), pOld)); } +// if any m_pResizeDrawObjects members are deleted during parse, remove them +// from m_pResizeDrawObjects and m_pDrawObjectPrcWidths +void HTMLTable::ObjectInDestruction(const SdrObject& rObject) +{ + auto it = std::find(m_pResizeDrawObjects->begin(), m_pResizeDrawObjects->end(), &rObject); + assert(it != m_pResizeDrawObjects->end()); + auto nIndex = std::distance(m_pResizeDrawObjects->begin(), it); + m_pResizeDrawObjects->erase(it); + auto otherit = m_pDrawObjectPrcWidths->begin() + nIndex * 3; + m_pDrawObjectPrcWidths->erase(otherit, otherit + 3); +} + HTMLTable::~HTMLTable() { m_pParser->DeregisterHTMLTable(this); - delete m_pResizeDrawObjects; + if (m_pResizeDrawObjects) + { + size_t nCount = m_pResizeDrawObjects->size(); + for (size_t i = 0; i < nCount; ++i) + { + SdrObject *pObj = (*m_pResizeDrawObjects)[i]; + pObj->RemoveObjectUser(*this); + } + delete m_pResizeDrawObjects; + } + delete m_pDrawObjectPrcWidths; delete m_pContext; @@ -2454,6 +2480,7 @@ void HTMLTable::RegisterDrawObject( SdrObject *pObj, sal_uInt8 nPrcWidth ) if( !m_pResizeDrawObjects ) m_pResizeDrawObjects = new SdrObjects; m_pResizeDrawObjects->push_back( pObj ); + pObj->AddObjectUser(*this); if( !m_pDrawObjectPrcWidths ) m_pDrawObjectPrcWidths = new std::vector; -- cgit v1.2.3