From 96bd77de5ad7b7a13f7e48e0f95c05ef49255aa0 Mon Sep 17 00:00:00 2001 From: Mike Kaganski Date: Mon, 13 Sep 2021 11:29:37 +0300 Subject: Use 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 --- editeng/source/items/xmlcnitm.cxx | 9 +++------ editeng/source/uno/unotext.cxx | 4 +--- 2 files changed, 4 insertions(+), 9 deletions(-) (limited to 'editeng') diff --git a/editeng/source/items/xmlcnitm.cxx b/editeng/source/items/xmlcnitm.cxx index 1e88121ee576..7bcfe11f9a55 100644 --- a/editeng/source/items/xmlcnitm.cxx +++ b/editeng/source/items/xmlcnitm.cxx @@ -18,6 +18,8 @@ */ #include + +#include #include #include #include @@ -75,13 +77,8 @@ bool SvXMLAttrContainerItem::QueryValue( css::uno::Any& rVal, sal_uInt8 /*nMembe bool SvXMLAttrContainerItem::PutValue( const css::uno::Any& rVal, sal_uInt8 /*nMemberId*/ ) { - SvUnoAttributeContainer* pContainer = nullptr; - Reference xTunnel(rVal, UNO_QUERY); - if( xTunnel.is() ) - pContainer = reinterpret_cast(static_cast(xTunnel->getSomething(SvUnoAttributeContainer::getUnoTunnelId()))); - - if( pContainer ) + if (auto pContainer = comphelper::getFromUnoTunnel(xTunnel)) { maContainerData = *pContainer->GetContainerImpl(); } diff --git a/editeng/source/uno/unotext.cxx b/editeng/source/uno/unotext.cxx index 3ad90c4709c3..92620d1951d3 100644 --- a/editeng/source/uno/unotext.cxx +++ b/editeng/source/uno/unotext.cxx @@ -2093,10 +2093,8 @@ void SvxUnoTextBase::copyText( SvxTextForwarder *pTextForwarder = pEditSource ? pEditSource->GetTextForwarder() : nullptr; if( !pTextForwarder ) return; - if( xUT.is() ) + if (auto pSource = comphelper::getFromUnoTunnel(xUT)) { - SvxUnoTextBase* pSource = reinterpret_cast(sal::static_int_cast( - xUT->getSomething( SvxUnoTextBase::getUnoTunnelId()))); SvxEditSource *pSourceEditSource = pSource->GetEditSource(); SvxTextForwarder *pSourceTextForwarder = pSourceEditSource ? pSourceEditSource->GetTextForwarder() : nullptr; if( pSourceTextForwarder ) -- cgit