diff options
author | Mike Kaganski <mike.kaganski@collabora.com> | 2017-09-29 17:33:15 +0300 |
---|---|---|
committer | Mike Kaganski <mike.kaganski@collabora.com> | 2017-09-30 19:08:28 +0200 |
commit | c3609f107b16eb888edf284f4637be6cb09234eb (patch) | |
tree | da52e05b5cdf26d5d3a57f510f8b32d8af10a026 /embedserv | |
parent | 8a4df9376bf299beb49fe116882ffdbd10b5e02b (diff) |
Use SAL_W/SAL_U instead of reinterpret_cast btwn wchar_t* and sal_Unicode*
This is type-safe, and allows to catch cases where a source type
is changed for some reason, but reinterpret_cast masks that
Change-Id: Ib64b6fa2e22d94a6bba890f0ccc3e20325c6f0a1
Reviewed-on: https://gerrit.libreoffice.org/42961
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Mike Kaganski <mike.kaganski@collabora.com>
Diffstat (limited to 'embedserv')
-rw-r--r-- | embedserv/source/embed/ed_ioleobject.cxx | 9 | ||||
-rw-r--r-- | embedserv/source/embed/ed_ipersiststr.cxx | 38 |
2 files changed, 22 insertions, 25 deletions
diff --git a/embedserv/source/embed/ed_ioleobject.cxx b/embedserv/source/embed/ed_ioleobject.cxx index 56ba1ecf5d4c..8e068ba3555d 100644 --- a/embedserv/source/embed/ed_ioleobject.cxx +++ b/embedserv/source/embed/ed_ioleobject.cxx @@ -44,10 +44,8 @@ STDMETHODIMP EmbedDocument_Impl::SetHostNames( LPCOLESTR szContainerApp, LPCOLES // the code should be ignored for links if ( !m_aFileName.getLength() ) { - m_pDocHolder->setTitle( - OUString(reinterpret_cast<sal_Unicode const *>(szContainerObj))); - m_pDocHolder->setContainerName( - OUString(reinterpret_cast<sal_Unicode const *>(szContainerApp))); + m_pDocHolder->setTitle(SAL_U(szContainerObj)); + m_pDocHolder->setContainerName(SAL_U(szContainerApp)); } return S_OK; @@ -419,8 +417,7 @@ HRESULT EmbedDocument_Impl::SaveObject() // in case of links the containers does not provide client site sometimes hr = Save( static_cast<LPCOLESTR>(nullptr), FALSE ); // triggers saving to the link location - SaveCompleted( - reinterpret_cast<wchar_t const *>(aPreservFileName.getStr())); + SaveCompleted(SAL_W(aPreservFileName.getStr())); } notify( false ); diff --git a/embedserv/source/embed/ed_ipersiststr.cxx b/embedserv/source/embed/ed_ipersiststr.cxx index 70c8b226a4df..bba4d2d59bc6 100644 --- a/embedserv/source/embed/ed_ipersiststr.cxx +++ b/embedserv/source/embed/ed_ipersiststr.cxx @@ -220,7 +220,7 @@ uno::Sequence< beans::PropertyValue > EmbedDocument_Impl::fillArgsForLoading_Imp uno::Reference< util::XURLTransformer > aTransformer( util::URLTransformer::create(comphelper::getComponentContext(m_xFactory)) ); util::URL aURL; - aURL.Complete = OUString( reinterpret_cast<const sal_Unicode*>(pFilePath) ); + aURL.Complete = SAL_U(pFilePath); if ( aTransformer->parseSmart( aURL, OUString() ) ) sDocUrl = aURL.Complete; @@ -429,7 +429,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) if ( hr == S_OK ) { - hr = pStg->CreateStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()), + hr = pStg->CreateStream( SAL_W(aOfficeEmbedStreamName.getStr()), STGM_CREATE | ( nStreamMode & 0x73 ), 0, 0, @@ -437,7 +437,7 @@ STDMETHODIMP EmbedDocument_Impl::InitNew( IStorage *pStg ) if ( hr == S_OK && m_pOwnStream ) { - hr = pStg->CreateStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()), + hr = pStg->CreateStream( SAL_W(aExtentStreamName.getStr()), STGM_CREATE | ( nStreamMode & 0x73 ), 0, 0, @@ -483,7 +483,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) if ( FAILED( hr ) ) return E_FAIL; DWORD nStreamMode = aStat.grfMode; - hr = pStg->OpenStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()), + hr = pStg->OpenStream( SAL_W(aOfficeEmbedStreamName.getStr()), nullptr, nStreamMode & 0x73, 0, @@ -492,7 +492,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) if ( SUCCEEDED( hr ) ) { - hr = pStg->OpenStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()), + hr = pStg->OpenStream( SAL_W(aExtentStreamName.getStr()), nullptr, nStreamMode & 0x73, 0, @@ -565,8 +565,8 @@ STDMETHODIMP EmbedDocument_Impl::Load( IStorage *pStg ) { m_pOwnStream = CComPtr< IStream >(); m_pExtStream = CComPtr< IStream >(); - hr = pStg->DestroyElement( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()) ); - hr = pStg->DestroyElement( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()) ); + hr = pStg->DestroyElement( SAL_W(aOfficeEmbedStreamName.getStr()) ); + hr = pStg->DestroyElement( SAL_W(aExtentStreamName.getStr()) ); OSL_ENSURE( SUCCEEDED( hr ), "Can not destroy created stream!" ); if ( FAILED( hr ) ) @@ -595,14 +595,14 @@ STDMETHODIMP EmbedDocument_Impl::Save( IStorage *pStgSave, BOOL fSameAsLoad ) if ( FAILED( hr ) ) return E_FAIL; DWORD nStreamMode = aStat.grfMode; - hr = pStgSave->CreateStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()), + hr = pStgSave->CreateStream( SAL_W(aOfficeEmbedStreamName.getStr()), STGM_CREATE | ( nStreamMode & 0x73 ), 0, 0, &pTargetStream ); if ( FAILED( hr ) || !pTargetStream ) return E_FAIL; - hr = pStgSave->CreateStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()), + hr = pStgSave->CreateStream( SAL_W(aExtentStreamName.getStr()), STGM_CREATE | ( nStreamMode & 0x73 ), 0, 0, @@ -690,14 +690,14 @@ STDMETHODIMP EmbedDocument_Impl::SaveCompleted( IStorage *pStgNew ) if ( FAILED( hr ) ) return E_OUTOFMEMORY; DWORD nStreamMode = aStat.grfMode; - hr = m_pMasterStorage->OpenStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()), + hr = m_pMasterStorage->OpenStream( SAL_W(aOfficeEmbedStreamName.getStr()), nullptr, nStreamMode & 0x73, 0, &m_pOwnStream ); if ( FAILED( hr ) || !m_pOwnStream ) return E_OUTOFMEMORY; - hr = m_pMasterStorage->OpenStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()), + hr = m_pMasterStorage->OpenStream( SAL_W(aExtentStreamName.getStr()), nullptr, nStreamMode & 0x73, 0, @@ -753,20 +753,20 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ ) CLIPFORMAT cf = (CLIPFORMAT)RegisterClipboardFormatW( L"Embedded Object" ); hr = WriteFmtUserTypeStg( m_pMasterStorage, cf, // ??? - const_cast<wchar_t *>(reinterpret_cast<wchar_t const *>(aCurType.data())) ); + const_cast<LPOLESTR>( SAL_W(aCurType.data())) ); if ( FAILED( hr ) ) return E_FAIL; hr = m_pMasterStorage->SetClass( m_guid ); if ( FAILED( hr ) ) return E_FAIL; - hr = m_pMasterStorage->CreateStream( reinterpret_cast<LPCWSTR>(aOfficeEmbedStreamName.getStr()), + hr = m_pMasterStorage->CreateStream( SAL_W(aOfficeEmbedStreamName.getStr()), STGM_CREATE | ( nStreamMode & 0x73 ), 0, 0, &m_pOwnStream ); if ( FAILED( hr ) || !m_pOwnStream ) return E_FAIL; - hr = m_pMasterStorage->CreateStream( reinterpret_cast<LPCWSTR>(aExtentStreamName.getStr()), + hr = m_pMasterStorage->CreateStream( SAL_W(aExtentStreamName.getStr()), STGM_CREATE | ( nStreamMode & 0x73 ), 0, 0, @@ -791,7 +791,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ ) pszFileName ) ); hr = S_OK; - m_aFileName = OUString( reinterpret_cast<const sal_Unicode*>(pszFileName) ); + m_aFileName = SAL_U(pszFileName); } catch( const uno::Exception& ) { @@ -804,7 +804,7 @@ STDMETHODIMP EmbedDocument_Impl::Load( LPCOLESTR pszFileName, DWORD /*dwMode*/ ) cf = (CLIPFORMAT)RegisterClipboardFormatW( L"Embedded Object" ); hr = WriteFmtUserTypeStg( m_pMasterStorage, cf, // ??? - const_cast<wchar_t *>(reinterpret_cast<wchar_t const *>(aCurType.data())) ); + const_cast<LPOLESTR>( SAL_W(aCurType.data())) ); if ( SUCCEEDED( hr ) ) { @@ -863,7 +863,7 @@ STDMETHODIMP EmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember ) else { util::URL aURL; - aURL.Complete = OUString( reinterpret_cast<const sal_Unicode*>( pszFileName ) ); + aURL.Complete = SAL_U( pszFileName ); uno::Reference< util::XURLTransformer > aTransformer( util::URLTransformer::create(comphelper::getComponentContext(m_xFactory)) ); @@ -891,7 +891,7 @@ STDMETHODIMP EmbedDocument_Impl::Save( LPCOLESTR pszFileName, BOOL fRemember ) STDMETHODIMP EmbedDocument_Impl::SaveCompleted( LPCOLESTR pszFileName ) { // the different file name would mean error here - m_aFileName = OUString( reinterpret_cast<const sal_Unicode*>(pszFileName) ); + m_aFileName = SAL_U(pszFileName); return S_OK; } @@ -903,7 +903,7 @@ STDMETHODIMP EmbedDocument_Impl::GetCurFile( LPOLESTR *ppszFileName ) if ( FAILED( hr ) || !pMalloc ) return E_FAIL; *ppszFileName = static_cast<LPOLESTR>( pMalloc->Alloc( sizeof( sal_Unicode ) * ( m_aFileName.getLength() + 1 ) ) ); - wcsncpy( *ppszFileName, reinterpret_cast<LPCWSTR>(m_aFileName.getStr()), m_aFileName.getLength() + 1 ); + wcsncpy( *ppszFileName, SAL_W(m_aFileName.getStr()), m_aFileName.getLength() + 1 ); return m_aFileName.getLength() ? S_OK : S_FALSE; } |