summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCaolán McNamara <caolanm@redhat.com>2021-11-01 17:34:23 +0000
committerCaolán McNamara <caolanm@redhat.com>2021-11-02 17:41:51 +0100
commit2f01faaf88b6d172d7293f0c9e2a061d99b8ceb5 (patch)
tree9d73a6951ff439f65d4b57a34f81158f6ea37add
parentedfb9ddb55d2959b8d05366233183306d19b3780 (diff)
ofz#40593 remove Objects from m_xResizeDrawObjects if deleted during parse
Change-Id: I11fa665175ef067a36f4822676c02d4df1e1e250 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/124563 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolanm@redhat.com>
-rw-r--r--sw/qa/core/data/html/pass/ofz40593-1.htmlbin0 -> 5192 bytes
-rw-r--r--sw/source/filter/html/htmltab.cxx32
2 files changed, 29 insertions, 3 deletions
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
--- /dev/null
+++ b/sw/qa/core/data/html/pass/ofz40593-1.html
Binary files differ
diff --git a/sw/source/filter/html/htmltab.cxx b/sw/source/filter/html/htmltab.cxx
index 7f39463b0fd6..7407988ce640 100644
--- a/sw/source/filter/html/htmltab.cxx
+++ b/sw/source/filter/html/htmltab.cxx
@@ -34,6 +34,7 @@
#include <svtools/htmlkywd.hxx>
#include <svl/numformat.hxx>
#include <svl/urihelper.hxx>
+#include <svx/sdrobjectuser.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
@@ -380,7 +381,7 @@ public:
// HTML table
typedef std::vector<SdrObject *> SdrObjects;
-class HTMLTable
+class HTMLTable : public sdr::ObjectUser
{
OUString m_aId;
OUString m_aStyle;
@@ -528,6 +529,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?
@@ -537,7 +540,7 @@ public:
bool bHasToFly,
const HTMLTableOptions& rOptions);
- ~HTMLTable();
+ virtual ~HTMLTable();
// Identifying of a cell
const HTMLTableCell& GetCell(sal_uInt16 nRow, sal_uInt16 nCell) const;
@@ -1071,11 +1074,33 @@ bool SwHTMLParser::IsReqIF() const
return m_bReqIF;
}
+// if any m_xResizeDrawObjects members are deleted during parse, remove them
+// from m_xResizeDrawObjects and m_xDrawObjectPercentWidths
+void HTMLTable::ObjectInDestruction(const SdrObject& rObject)
+{
+ auto it = std::find(m_xResizeDrawObjects->begin(), m_xResizeDrawObjects->end(), &rObject);
+ assert(it != m_xResizeDrawObjects->end());
+ auto nIndex = std::distance(m_xResizeDrawObjects->begin(), it);
+ m_xResizeDrawObjects->erase(it);
+ auto otherit = m_xDrawObjectPercentWidths->begin() + nIndex * 3;
+ m_xDrawObjectPercentWidths->erase(otherit, otherit + 3);
+}
+
HTMLTable::~HTMLTable()
{
m_pParser->DeregisterHTMLTable(this);
- m_xResizeDrawObjects.reset();
+ if (m_xResizeDrawObjects)
+ {
+ size_t nCount = m_xResizeDrawObjects->size();
+ for (size_t i = 0; i < nCount; ++i)
+ {
+ SdrObject *pObj = (*m_xResizeDrawObjects)[i];
+ pObj->RemoveObjectUser(*this);
+ m_xResizeDrawObjects.reset();
+ }
+ }
+
m_xDrawObjectPercentWidths.reset();
m_pContext.reset();
@@ -2477,6 +2502,7 @@ void HTMLTable::RegisterDrawObject( SdrObject *pObj, sal_uInt8 nPercentWidth )
if( !m_xResizeDrawObjects )
m_xResizeDrawObjects.emplace();
m_xResizeDrawObjects->push_back( pObj );
+ pObj->AddObjectUser(*this);
if( !m_xDrawObjectPercentWidths )
m_xDrawObjectPercentWidths.emplace();