summaryrefslogtreecommitdiff
path: root/connectivity
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 /connectivity
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 'connectivity')
-rw-r--r--connectivity/source/drivers/ado/ADriver.cxx5
-rw-r--r--connectivity/source/drivers/dbase/DIndex.cxx2
-rw-r--r--connectivity/source/drivers/dbase/DIndexes.cxx2
-rw-r--r--connectivity/source/drivers/dbase/DTable.cxx12
-rw-r--r--connectivity/source/drivers/dbase/DTables.cxx2
-rw-r--r--connectivity/source/drivers/file/FResultSet.cxx2
-rw-r--r--connectivity/source/drivers/file/FStatement.cxx7
7 files changed, 14 insertions, 18 deletions
diff --git a/connectivity/source/drivers/ado/ADriver.cxx b/connectivity/source/drivers/ado/ADriver.cxx
index e2d8cc2aa730..3cdfeab26888 100644
--- a/connectivity/source/drivers/ado/ADriver.cxx
+++ b/connectivity/source/drivers/ado/ADriver.cxx
@@ -24,6 +24,7 @@
#include <ado/Awrapado.hxx>
#include <ado/adoimp.hxx>
#include <com/sun/star/lang/DisposedException.hpp>
+#include <comphelper/servicehelper.hxx>
#include <connectivity/dbexception.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <o3tl/safeCoInitUninit.hxx>
@@ -170,10 +171,8 @@ Reference< XTablesSupplier > SAL_CALL ODriver::getDataDefinitionByConnection( co
OConnection* pConnection = nullptr;
Reference< css::lang::XUnoTunnel> xTunnel(connection,UNO_QUERY);
- if(xTunnel.is())
+ if (auto pSearchConnection = comphelper::getFromUnoTunnel<OConnection>(xTunnel))
{
- OConnection* pSearchConnection = reinterpret_cast< OConnection* >( xTunnel->getSomething(OConnection::getUnoTunnelId()) );
-
auto foundConnection = std::any_of(m_xConnections.begin(), m_xConnections.end(),
[&pSearchConnection](const css::uno::WeakReferenceHelper& rxConnection) {
return static_cast<OConnection*>(Reference< XConnection >::query(rxConnection.get()).get()) == pSearchConnection; });
diff --git a/connectivity/source/drivers/dbase/DIndex.cxx b/connectivity/source/drivers/dbase/DIndex.cxx
index ca2e3e107e1a..462756993cad 100644
--- a/connectivity/source/drivers/dbase/DIndex.cxx
+++ b/connectivity/source/drivers/dbase/DIndex.cxx
@@ -566,7 +566,7 @@ void ODbaseIndex::CreateImpl()
if(xSet->last())
{
Reference< XUnoTunnel> xTunnel(xSet, UNO_QUERY_THROW);
- ODbaseResultSet* pDbaseRes = reinterpret_cast< ODbaseResultSet* >( xTunnel->getSomething(ODbaseResultSet::getUnoTunnelId()) );
+ ODbaseResultSet* pDbaseRes = comphelper::getFromUnoTunnel<ODbaseResultSet>(xTunnel);
assert(pDbaseRes); //"No dbase resultset found? What's going on here!
nRowsLeft = xSet->getRow();
diff --git a/connectivity/source/drivers/dbase/DIndexes.cxx b/connectivity/source/drivers/dbase/DIndexes.cxx
index d97e1187b5fd..7f47085c6509 100644
--- a/connectivity/source/drivers/dbase/DIndexes.cxx
+++ b/connectivity/source/drivers/dbase/DIndexes.cxx
@@ -95,7 +95,7 @@ sdbcx::ObjectType ODbaseIndexes::appendObject( const OUString& _rForName, const
Reference<XUnoTunnel> xTunnel(descriptor,UNO_QUERY);
if(xTunnel.is())
{
- ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) );
+ ODbaseIndex* pIndex = comphelper::getFromUnoTunnel<ODbaseIndex>(xTunnel);
if(!pIndex)
throw SQLException();
pIndex->CreateImpl();
diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx
index 8ffb7775af4b..39ea5e22da79 100644
--- a/connectivity/source/drivers/dbase/DTable.cxx
+++ b/connectivity/source/drivers/dbase/DTable.cxx
@@ -1561,8 +1561,8 @@ bool ODbaseTable::DeleteRow(const OSQLColumns& _rCols)
Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY);
OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!");
- ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) );
- OSL_ENSURE(pIndex,"ODbaseTable::DeleteRow: No Index returned!");
+ ODbaseIndex* pIndex = comphelper::getFromUnoTunnel<ODbaseIndex>(xTunnel);
+ assert(pIndex && "ODbaseTable::DeleteRow: No Index returned!");
OSQLColumns::const_iterator aIter = std::find_if(_rCols.begin(), _rCols.end(),
[&aCase, &aColName](const OSQLColumns::value_type& rxCol) {
@@ -1667,8 +1667,8 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
{
Reference<XUnoTunnel> xTunnel(xIndex,UNO_QUERY);
OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!");
- ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) );
- OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!");
+ ODbaseIndex* pIndex = comphelper::getFromUnoTunnel<ODbaseIndex>(xTunnel);
+ assert(pIndex && "ODbaseTable::UpdateBuffer: No Index returned!");
if (pIndex->Find(0,*rRow[nPos]))
{
@@ -1775,8 +1775,8 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
{
Reference<XUnoTunnel> xTunnel(aIndexedCols[i],UNO_QUERY);
OSL_ENSURE(xTunnel.is(),"No TunnelImplementation!");
- ODbaseIndex* pIndex = reinterpret_cast< ODbaseIndex* >( xTunnel->getSomething(ODbaseIndex::getUnoTunnelId()) );
- OSL_ENSURE(pIndex,"ODbaseTable::UpdateBuffer: No Index returned!");
+ ODbaseIndex* pIndex = comphelper::getFromUnoTunnel<ODbaseIndex>(xTunnel);
+ assert(pIndex && "ODbaseTable::UpdateBuffer: No Index returned!");
// Update !!
if (pOrgRow.is() && !thisColIsNull)
pIndex->Update(m_nFilePos, *(*pOrgRow)[nPos], thisColVal);
diff --git a/connectivity/source/drivers/dbase/DTables.cxx b/connectivity/source/drivers/dbase/DTables.cxx
index 266816eeb776..a3bc953d93b4 100644
--- a/connectivity/source/drivers/dbase/DTables.cxx
+++ b/connectivity/source/drivers/dbase/DTables.cxx
@@ -103,7 +103,7 @@ void ODbaseTables::dropObject(sal_Int32 _nPos, const OUString& _sElementName)
if ( xTunnel.is() )
{
- ODbaseTable* pTable = reinterpret_cast< ODbaseTable* >( xTunnel->getSomething(ODbaseTable::getUnoTunnelId()) );
+ ODbaseTable* pTable = comphelper::getFromUnoTunnel<ODbaseTable>(xTunnel);
if(pTable)
pTable->DropImpl();
}
diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx
index 0a4040ddc590..56ed6134c387 100644
--- a/connectivity/source/drivers/file/FResultSet.cxx
+++ b/connectivity/source/drivers/file/FResultSet.cxx
@@ -1528,7 +1528,7 @@ Reference< css::beans::XPropertySetInfo > SAL_CALL OResultSet::getPropertySetInf
void OResultSet::doTableSpecials(const OSQLTable& _xTable)
{
Reference<css::lang::XUnoTunnel> xTunnel(_xTable, UNO_QUERY_THROW);
- m_pTable = reinterpret_cast< OFileTable* >(xTunnel->getSomething(OFileTable::getUnoTunnelId()));
+ m_pTable = comphelper::getFromUnoTunnel<OFileTable>(xTunnel);
assert(m_pTable.is());
}
diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx
index 30ebb42f252d..3c751f0d1ee4 100644
--- a/connectivity/source/drivers/file/FStatement.cxx
+++ b/connectivity/source/drivers/file/FStatement.cxx
@@ -32,6 +32,7 @@
#include <com/sun/star/sdbc/FetchDirection.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <comphelper/sequence.hxx>
+#include <comphelper/servicehelper.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <comphelper/types.hxx>
#include <connectivity/dbexception.hxx>
@@ -406,11 +407,7 @@ void OStatement_Base::construct(const OUString& sql)
}
// at this moment we support only one table per select statement
- Reference< css::lang::XUnoTunnel> xTunnel(rTabs.begin()->second,UNO_QUERY);
- if(xTunnel.is())
- {
- m_pTable = reinterpret_cast<OFileTable*>(xTunnel->getSomething(OFileTable::getUnoTunnelId()));
- }
+ m_pTable = comphelper::getFromUnoTunnel<OFileTable>(rTabs.begin()->second);
OSL_ENSURE(m_pTable.is(),"No table!");
if ( m_pTable.is() )
m_xColNames = m_pTable->getColumns();