summaryrefslogtreecommitdiff
path: root/sw/source/filter/xml
diff options
context:
space:
mode:
authorMike Kaganski <mike.kaganski@collabora.com>2021-09-13 11:29:37 +0300
committerMike Kaganski <mike.kaganski@collabora.com>2021-09-15 06:08:27 +0200
commit96bd77de5ad7b7a13f7e48e0f95c05ef49255aa0 (patch)
tree4c79c57712124a8589c9e6579b6ec7fec9200c3b /sw/source/filter/xml
parent3f65724ec5fc92d5a0078a99932358ef7091435c (diff)
Use <comphelper/servicehelper.hxx> implementing XUnoTunnel part 5
- Revise uses of getSomething to use getFromUnoTunnel Where that is impossible, use getSomething_cast to unify casting, and minimize number of places doing low-level transformations. The change keeps the existing tunnel references that last for the duration of the pointers' life, because sometimes destroying such reference may destroy the pointed object, and result in use after free. Change-Id: I291c33223582c34cd2c763aa8aacf0ae899ca4c0 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/122101 Tested-by: Jenkins Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'sw/source/filter/xml')
-rw-r--r--sw/source/filter/xml/xmlexp.cxx3
-rw-r--r--sw/source/filter/xml/xmlimp.cxx13
-rw-r--r--sw/source/filter/xml/xmltble.cxx8
-rw-r--r--sw/source/filter/xml/xmltbli.cxx17
-rw-r--r--sw/source/filter/xml/xmltexte.cxx3
-rw-r--r--sw/source/filter/xml/xmltexti.cxx21
6 files changed, 17 insertions, 48 deletions
diff --git a/sw/source/filter/xml/xmlexp.cxx b/sw/source/filter/xml/xmlexp.cxx
index f0255f7833f2..437a1a9c76f6 100644
--- a/sw/source/filter/xml/xmlexp.cxx
+++ b/sw/source/filter/xml/xmlexp.cxx
@@ -501,8 +501,7 @@ SwDoc* SwXMLExport::getDoc()
Reference < XText > xText = xTextDoc->getText();
Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
assert( xTextTunnel.is());
- SwXText *pText = reinterpret_cast< SwXText *>(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
+ SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xTextTunnel);
assert( pText != nullptr );
m_pDoc = pText->GetDoc();
assert( m_pDoc != nullptr );
diff --git a/sw/source/filter/xml/xmlimp.cxx b/sw/source/filter/xml/xmlimp.cxx
index 6bfdcf0f0698..eea1ca435720 100644
--- a/sw/source/filter/xml/xmlimp.cxx
+++ b/sw/source/filter/xml/xmlimp.cxx
@@ -374,12 +374,7 @@ sal_Int64 SAL_CALL SwXMLImport::getSomething( const Sequence< sal_Int8 >& rId )
static OTextCursorHelper *lcl_xml_GetSwXTextCursor( const Reference < XTextCursor >& rTextCursor )
{
- Reference<XUnoTunnel> xCursorTunnel( rTextCursor, UNO_QUERY );
- OSL_ENSURE( xCursorTunnel.is(), "missing XUnoTunnel for Cursor" );
- if( !xCursorTunnel.is() )
- return nullptr;
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper *>(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(rTextCursor);
OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
return pTextCursor;
}
@@ -648,8 +643,7 @@ void SwXMLImport::endDocument()
Reference<XUnoTunnel> xCursorTunnel( GetTextImport()->GetCursor(),
UNO_QUERY);
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper *>(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
assert(pTextCursor && "SwXTextCursor missing");
SwPaM *pPaM = pTextCursor->GetPaM();
if( IsInsertMode() && m_pSttNdIdx->GetIndex() )
@@ -1655,8 +1649,7 @@ SwDoc* SwXMLImport::getDoc()
Reference < XText > xText = xTextDoc->getText();
Reference<XUnoTunnel> xTextTunnel( xText, UNO_QUERY);
assert( xTextTunnel.is());
- SwXText *pText = reinterpret_cast< SwXText *>(
- sal::static_int_cast< sal_IntPtr >( xTextTunnel->getSomething( SwXText::getUnoTunnelId() )));
+ SwXText* pText = comphelper::getFromUnoTunnel<SwXText>(xTextTunnel);
assert( pText != nullptr );
m_pDoc = pText->GetDoc();
assert( m_pDoc != nullptr );
diff --git a/sw/source/filter/xml/xmltble.cxx b/sw/source/filter/xml/xmltble.cxx
index 4787961efcb4..3a3409cd1b46 100644
--- a/sw/source/filter/xml/xmltble.cxx
+++ b/sw/source/filter/xml/xmltble.cxx
@@ -1212,14 +1212,8 @@ void SwXMLTextParagraphExport::exportTable(
OSL_ENSURE( xTextTable.is(), "text table missing" );
if( xTextTable.is() )
{
- SwXTextTable *pXTable = nullptr;
Reference<XUnoTunnel> xTableTunnel( rTextContent, UNO_QUERY);
- if( xTableTunnel.is() )
- {
- pXTable = reinterpret_cast< SwXTextTable * >(
- sal::static_int_cast< sal_IntPtr >( xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() )));
- OSL_ENSURE( pXTable, "SwXTextTable missing" );
- }
+ SwXTextTable* pXTable = comphelper::getFromUnoTunnel<SwXTextTable>(xTableTunnel);
if( pXTable )
{
SwFrameFormat *const pFormat = pXTable->GetFrameFormat();
diff --git a/sw/source/filter/xml/xmltbli.cxx b/sw/source/filter/xml/xmltbli.cxx
index 439c7df0f631..a071ce35ec67 100644
--- a/sw/source/filter/xml/xmltbli.cxx
+++ b/sw/source/filter/xml/xmltbli.cxx
@@ -595,8 +595,7 @@ void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 )
// Until we have an API for copying we have to use the core.
Reference<XUnoTunnel> xSrcCursorTunnel( xSrcTextCursor, UNO_QUERY);
assert(xSrcCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pSrcTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xSrcCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper *pSrcTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xSrcTextCursor);
assert(pSrcTextCursor && "SwXTextCursor missing");
SwDoc *pDoc = pSrcTextCursor->GetDoc();
const SwPaM *pSrcPaM = pSrcTextCursor->GetPaM();
@@ -608,8 +607,7 @@ void SwXMLTableCellContext_Impl::endFastElement(sal_Int32 )
Reference<XUnoTunnel> xDstCursorTunnel(
GetImport().GetTextImport()->GetCursor(), UNO_QUERY);
assert(xDstCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pDstTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xDstCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )) );
+ OTextCursorHelper *pDstTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(GetImport().GetTextImport()->GetCursor());
assert(pDstTextCursor && "SwXTextCursor missing");
SwPaM aSrcPaM(*pSrcPaM->GetMark(), *pSrcPaM->GetPoint());
SwPosition aDstPos( *pDstTextCursor->GetPaM()->GetPoint() );
@@ -1220,13 +1218,7 @@ SwXMLTableContext::SwXMLTableContext( SwXMLImport& rImport,
// xml:id for RDF metadata
GetImport().SetXmlId(xTable, sXmlId);
- Reference<XUnoTunnel> xTableTunnel( xTable, UNO_QUERY);
- if( xTableTunnel.is() )
- {
- pXTable = reinterpret_cast< SwXTextTable * >(
- sal::static_int_cast< sal_IntPtr >( xTableTunnel->getSomething( SwXTextTable::getUnoTunnelId() )));
- OSL_ENSURE( pXTable, "SwXTextTable missing" );
- }
+ pXTable = comphelper::getFromUnoTunnel<SwXTextTable>(xTable);
Reference < XCellRange > xCellRange( xTable, UNO_QUERY );
Reference < XCell > xCell = xCellRange->getCellByPosition( 0, 0 );
@@ -2698,8 +2690,7 @@ const SwStartNode *SwXMLTableContext::InsertTableSection(
Reference<XUnoTunnel> xCursorTunnel( GetImport().GetTextImport()->GetCursor(),
UNO_QUERY);
OSL_ENSURE( xCursorTunnel.is(), "missing XUnoTunnel for Cursor" );
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper *pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
if( m_bFirstSection )
diff --git a/sw/source/filter/xml/xmltexte.cxx b/sw/source/filter/xml/xmltexte.cxx
index 0210db520e6d..e5b8dc181aef 100644
--- a/sw/source/filter/xml/xmltexte.cxx
+++ b/sw/source/filter/xml/xmltexte.cxx
@@ -72,8 +72,7 @@ SwNoTextNode *SwXMLTextParagraphExport::GetNoTextNode(
{
Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded");
- SwXFrame *pFrame = reinterpret_cast< SwXFrame * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( SwXFrame::getUnoTunnelId() )));
+ SwXFrame* pFrame = comphelper::getFromUnoTunnel<SwXFrame>(xCursorTunnel);
assert(pFrame && "SwXFrame missing");
SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat();
const SwFormatContent& rContent = pFrameFormat->GetContent();
diff --git a/sw/source/filter/xml/xmltexti.cxx b/sw/source/filter/xml/xmltexti.cxx
index 0c10b3ba9eb0..f73ef35be731 100644
--- a/sw/source/filter/xml/xmltexti.cxx
+++ b/sw/source/filter/xml/xmltexti.cxx
@@ -191,8 +191,7 @@ bool SwXMLTextImportHelper::IsInHeaderFooter() const
uno::Reference<XUnoTunnel> xCursorTunnel(
const_cast<SwXMLTextImportHelper *>(this)->GetCursor(), UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
SAL_WARN_IF(!pTextCursor, "sw.uno", "SwXTextCursor missing");
SwDoc *pDoc = pTextCursor ? pTextCursor->GetDoc() : nullptr;
@@ -235,8 +234,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOLEObject(
uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
SAL_WARN_IF(!pTextCursor, "sw.uno", "SwXTextCursor missing");
SwDoc *pDoc = SwImport::GetDocFromXMLImport( rImport );
@@ -547,8 +545,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertOOoLink(
uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
SwDoc *pDoc = SwImport::GetDocFromXMLImport( rImport );
@@ -639,8 +636,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertApplet(
uno::Reference < XPropertySet > xPropSet;
uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
SwDoc *pDoc = pTextCursor->GetDoc();
@@ -685,8 +681,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertPlugin(
uno::Reference < XPropertySet > xPropSet;
uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
SwDoc *pDoc = pTextCursor->GetDoc();
@@ -766,8 +761,7 @@ uno::Reference< XPropertySet > SwXMLTextImportHelper::createAndInsertFloatingFra
uno::Reference < XPropertySet > xPropSet;
uno::Reference<XUnoTunnel> xCursorTunnel( GetCursor(), UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for Cursor");
- OTextCursorHelper *pTextCursor = reinterpret_cast< OTextCursorHelper * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( OTextCursorHelper::getUnoTunnelId() )));
+ OTextCursorHelper* pTextCursor = comphelper::getFromUnoTunnel<OTextCursorHelper>(xCursorTunnel);
OSL_ENSURE( pTextCursor, "SwXTextCursor missing" );
SwDoc *pDoc = pTextCursor->GetDoc();
@@ -916,8 +910,7 @@ void SwXMLTextImportHelper::endAppletOrPlugin(
uno::Reference<XUnoTunnel> xCursorTunnel( rPropSet, UNO_QUERY );
assert(xCursorTunnel.is() && "missing XUnoTunnel for embedded");
- SwXFrame *pFrame = reinterpret_cast< SwXFrame * >(
- sal::static_int_cast< sal_IntPtr >( xCursorTunnel->getSomething( SwXFrame::getUnoTunnelId() )));
+ SwXFrame* pFrame = comphelper::getFromUnoTunnel<SwXFrame>(xCursorTunnel);
OSL_ENSURE( pFrame, "SwXFrame missing" );
SwFrameFormat *pFrameFormat = pFrame->GetFrameFormat();
const SwFormatContent& rContent = pFrameFormat->GetContent();