summaryrefslogtreecommitdiff
path: root/sc
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 /sc
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 'sc')
-rw-r--r--sc/source/ui/app/drwtrans.cxx14
-rw-r--r--sc/source/ui/app/transobj.cxx14
-rw-r--r--sc/source/ui/vba/excelvbahelper.hxx9
-rw-r--r--sc/source/ui/view/viewfun3.cxx18
4 files changed, 9 insertions, 46 deletions
diff --git a/sc/source/ui/app/drwtrans.cxx b/sc/source/ui/app/drwtrans.cxx
index 180571472da5..50075e80055f 100644
--- a/sc/source/ui/app/drwtrans.cxx
+++ b/sc/source/ui/app/drwtrans.cxx
@@ -230,19 +230,7 @@ ScDrawTransferObj::~ScDrawTransferObj()
ScDrawTransferObj* ScDrawTransferObj::GetOwnClipboard(const uno::Reference<datatransfer::XTransferable2>& xTransferable)
{
- ScDrawTransferObj* pObj = nullptr;
- if (xTransferable.is())
- {
- uno::Reference<XUnoTunnel> xTunnel( xTransferable, uno::UNO_QUERY );
- if ( xTunnel.is() )
- {
- sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
- if ( nHandle )
- pObj = dynamic_cast<ScDrawTransferObj*>(reinterpret_cast<TransferableHelper*>( static_cast<sal_IntPtr>(nHandle) ));
- }
- }
-
- return pObj;
+ return comphelper::getFromUnoTunnel<ScDrawTransferObj>(xTransferable);
}
static bool lcl_HasOnlyControls( SdrModel* pModel )
diff --git a/sc/source/ui/app/transobj.cxx b/sc/source/ui/app/transobj.cxx
index 9a3d12059945..0af2328f24c3 100644
--- a/sc/source/ui/app/transobj.cxx
+++ b/sc/source/ui/app/transobj.cxx
@@ -193,19 +193,7 @@ ScTransferObj::~ScTransferObj()
ScTransferObj* ScTransferObj::GetOwnClipboard(const uno::Reference<datatransfer::XTransferable2>& xTransferable)
{
- ScTransferObj* pObj = nullptr;
- if (xTransferable.is())
- {
- uno::Reference<XUnoTunnel> xTunnel( xTransferable, uno::UNO_QUERY );
- if ( xTunnel.is() )
- {
- sal_Int64 nHandle = xTunnel->getSomething( getUnoTunnelId() );
- if ( nHandle )
- pObj = dynamic_cast<ScTransferObj*>(reinterpret_cast<TransferableHelper*>( static_cast<sal_IntPtr>(nHandle) ));
- }
- }
-
- return pObj;
+ return comphelper::getFromUnoTunnel<ScTransferObj>(xTransferable);
}
void ScTransferObj::AddSupportedFormats()
diff --git a/sc/source/ui/vba/excelvbahelper.hxx b/sc/source/ui/vba/excelvbahelper.hxx
index 41d9cc0a2df1..3d3cf42b95aa 100644
--- a/sc/source/ui/vba/excelvbahelper.hxx
+++ b/sc/source/ui/vba/excelvbahelper.hxx
@@ -18,6 +18,10 @@
*/
#pragma once
+#include <sal/config.h>
+
+#include <comphelper/servicehelper.hxx>
+
#include <com/sun/star/lang/XUnoTunnel.hpp>
#include <vector>
#include <global.hxx>
@@ -83,10 +87,7 @@ public:
template < typename ImplObject >
ImplObject* getImplFromDocModuleWrapper( const css::uno::Reference< css::uno::XInterface >& rxWrapperIf )
{
- ImplObject* pObj = nullptr;
- css::uno::Reference< css::lang::XUnoTunnel > xTunnel( rxWrapperIf, css::uno::UNO_QUERY );
- if ( xTunnel.is() )
- pObj = reinterpret_cast<ImplObject*>( xTunnel->getSomething(ImplObject::getUnoTunnelId()));
+ ImplObject* pObj = comphelper::getFromUnoTunnel<ImplObject>(rxWrapperIf);
if ( !pObj )
throw css::uno::RuntimeException("Internal error, can't extract implementation object", rxWrapperIf );
return pObj;
diff --git a/sc/source/ui/view/viewfun3.cxx b/sc/source/ui/view/viewfun3.cxx
index 1b4efb7cea77..fd14410929ad 100644
--- a/sc/source/ui/view/viewfun3.cxx
+++ b/sc/source/ui/view/viewfun3.cxx
@@ -619,29 +619,15 @@ void ScViewFunc::PasteFromSystem()
void ScViewFunc::PasteFromTransferable( const uno::Reference<datatransfer::XTransferable>& rxTransferable )
{
- ScTransferObj *pOwnClip=nullptr;
- ScDrawTransferObj *pDrawClip=nullptr;
uno::Reference<lang::XUnoTunnel> xTunnel( rxTransferable, uno::UNO_QUERY );
- if ( xTunnel.is() )
- {
- sal_Int64 nHandle = xTunnel->getSomething( ScTransferObj::getUnoTunnelId() );
- if ( nHandle )
- pOwnClip = reinterpret_cast<ScTransferObj*>( static_cast<sal_IntPtr>(nHandle));
- else
- {
- nHandle = xTunnel->getSomething( ScDrawTransferObj::getUnoTunnelId() );
- if ( nHandle )
- pDrawClip = reinterpret_cast<ScDrawTransferObj*>( static_cast<sal_IntPtr>(nHandle) );
- }
- }
- if (pOwnClip)
+ if (auto pOwnClip = comphelper::getFromUnoTunnel<ScTransferObj>(xTunnel))
{
PasteFromClip( InsertDeleteFlags::ALL, pOwnClip->GetDocument(),
ScPasteFunc::NONE, false, false, false, INS_NONE, InsertDeleteFlags::NONE,
true ); // allow warning dialog
}
- else if (pDrawClip)
+ else if (auto pDrawClip = comphelper::getFromUnoTunnel<ScDrawTransferObj>(xTunnel))
{
ScViewData& rViewData = GetViewData();
SCCOL nPosX = rViewData.GetCurX();