diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-29 09:23:41 +0500 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2024-07-29 15:21:39 +0200 |
commit | 18ed2be7f1406b879c1add35f8f86e68202d0876 (patch) | |
tree | 917fdba0b44fa0bc2427262323503726880b91df /package/source/xstor | |
parent | c39978f41dccbeb2e973c919a67d9b1d974f8f3c (diff) |
Prevent rtl::Reference -> css::uno::Reference -> rtl::Reference implicit path
Replace up-casting conversion constructor with respective conversion operator,
similar to existing css::uno::Reference conversion operator. Thic change will
not allow code like
rtl::Reference<Foo> foo;
rtl::Reference<Foo> bar(foo, uno::UNO_QUERY_THROW);
which was possible because compiler could use temporary css::uno::Reference.
Change-Id: I54b79af3e2508b26e9cd59f2cc7e2ae92f6efbbf
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/171166
Tested-by: Jenkins
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'package/source/xstor')
-rw-r--r-- | package/source/xstor/ohierarchyholder.cxx | 32 | ||||
-rw-r--r-- | package/source/xstor/ohierarchyholder.hxx | 4 |
2 files changed, 13 insertions, 23 deletions
diff --git a/package/source/xstor/ohierarchyholder.cxx b/package/source/xstor/ohierarchyholder.cxx index d8dcb1e70723..66b8043748ea 100644 --- a/package/source/xstor/ohierarchyholder.cxx +++ b/package/source/xstor/ohierarchyholder.cxx @@ -39,8 +39,6 @@ using namespace ::com::sun::star; uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStreamHierarchically( sal_Int32 nStorageMode, std::vector<OUString>& aListPath, sal_Int32 nStreamMode, const ::comphelper::SequenceAsHashMap& aEncryptionData ) { - rtl::Reference< OStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); - if ( !( nStorageMode & embed::ElementModes::WRITE ) && ( nStreamMode & embed::ElementModes::WRITE ) ) throw io::IOException(u"invalid storage/stream mode combo"_ustr); @@ -54,8 +52,6 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyHolder_Impl::GetStream void OHierarchyHolder_Impl::RemoveStreamHierarchically( std::vector<OUString>& aListPath ) { - rtl::Reference< OStorage > xOwnStor( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); - m_xChild->RemoveStreamHierarchically( aListPath ); } @@ -95,20 +91,16 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea uno::Reference< embed::XExtendedStorageStream > xResult; rtl::Reference< OStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage - : rtl::Reference< OStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); + : m_xWeakOwnStorage.get(); + if (!xOwnStor) + throw uno::RuntimeException(u"no own storage"_ustr); if ( aListPath.empty() ) { if ( aEncryptionData.empty() ) - { - rtl::Reference< OStorage > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - xResult = xHStorage->openStreamElementByHierarchicalName( aNextName, nStreamMode ); - } + xResult = xOwnStor->openStreamElementByHierarchicalName( aNextName, nStreamMode ); else - { - rtl::Reference< OStorage > xHStorage( xOwnStor, uno::UNO_QUERY_THROW ); - xResult = xHStorage->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() ); - } + xResult = xOwnStor->openEncryptedStreamByHierarchicalName( aNextName, nStreamMode, aEncryptionData.getAsConstNamedValueList() ); uno::Reference< embed::XTransactedObject > xTransact( xResult, uno::UNO_QUERY ); if ( xTransact.is() ) @@ -156,7 +148,7 @@ uno::Reference< embed::XExtendedStorageStream > OHierarchyElement_Impl::GetStrea } // the subelement was opened successfully, remember the storage to let it be locked - m_xOwnStorage = xOwnStor; + m_xOwnStorage = std::move(xOwnStor); return xResult; } @@ -172,7 +164,9 @@ void OHierarchyElement_Impl::RemoveStreamHierarchically( std::vector<OUString>& aListPath.erase( aListPath.begin() ); rtl::Reference< OStorage > xOwnStor = m_xOwnStorage.is() ? m_xOwnStorage - : rtl::Reference< OStorage >( m_xWeakOwnStorage.get(), uno::UNO_QUERY_THROW ); + : m_xWeakOwnStorage.get(); + if (!xOwnStor) + throw uno::RuntimeException(u"no own storage"_ustr); if ( aListPath.empty() ) { @@ -198,8 +192,7 @@ void OHierarchyElement_Impl::RemoveStreamHierarchically( std::vector<OUString>& aElement->RemoveStreamHierarchically( aListPath ); } - if ( xOwnStor.is() ) - xOwnStor->commit(); + xOwnStor->commit(); TestForClosing(); } @@ -208,7 +201,7 @@ void OHierarchyElement_Impl::Commit() { ::rtl::Reference< OHierarchyElement_Impl > xKeepAlive( this ); ::rtl::Reference< OHierarchyElement_Impl > aParent; - uno::Reference< embed::XStorage > xOwnStor; + rtl::Reference<OStorage> xOwnStor; { std::unique_lock aGuard( m_aMutex ); @@ -218,8 +211,7 @@ void OHierarchyElement_Impl::Commit() if ( xOwnStor.is() ) { - uno::Reference< embed::XTransactedObject > xTransact( xOwnStor, uno::UNO_QUERY_THROW ); - xTransact->commit(); + xOwnStor->commit(); if ( aParent.is() ) aParent->Commit(); } diff --git a/package/source/xstor/ohierarchyholder.hxx b/package/source/xstor/ohierarchyholder.hxx index 6ab833870507..10e6ca379800 100644 --- a/package/source/xstor/ohierarchyholder.hxx +++ b/package/source/xstor/ohierarchyholder.hxx @@ -94,12 +94,10 @@ public: class OHierarchyHolder_Impl : public ::cppu::OWeakObject { - unotools::WeakReference< OStorage > m_xWeakOwnStorage; ::rtl::Reference< OHierarchyElement_Impl > m_xChild; public: explicit OHierarchyHolder_Impl( const rtl::Reference< OStorage >& xOwnStorage ) - : m_xWeakOwnStorage( xOwnStorage ) - , m_xChild( new OHierarchyElement_Impl( unotools::WeakReference< OStorage >( xOwnStorage ) ) ) + : m_xChild( new OHierarchyElement_Impl( unotools::WeakReference< OStorage >( xOwnStorage ) ) ) {} static std::vector<OUString> GetListPathFromString( std::u16string_view aPath ); |