include/sot/stg.hxx | 6 +++--- sot/source/sdstor/stg.cxx | 18 +++++++++--------- sot/source/sdstor/stgavl.cxx | 5 +++-- sot/source/sdstor/storage.cxx | 2 +- sot/source/sdstor/ucbstorage.cxx | 24 ++++++++++++------------ sot/source/unoolestorage/xolesimplestorage.cxx | 2 +- svl/source/items/style.cxx | 2 +- svl/source/misc/strmadpt.cxx | 1 + svl/source/misc/urihelper.cxx | 2 +- 9 files changed, 32 insertions(+), 30 deletions(-)
New commits: commit fdbc8d1374e2a9fde6c99acbe6923a277695a0a3 Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Apr 30 20:08:04 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed May 1 09:17:27 2024 +0200 WaE: C6011 Dereferencing NULL pointer warnings Change-Id: Ie1aff54bbc2d9dad0298636bf680ac7790f70a72 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166941 Tested-by: Jenkins Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx index 2b3e9a146908..86658536cb07 100644 --- a/sot/source/sdstor/stg.cxx +++ b/sot/source/sdstor/stg.cxx @@ -440,7 +440,7 @@ void Storage::Init( bool bCreate ) bool bHdrLoaded = false; bIsRoot = true; - OSL_ENSURE( pIo, "The pointer may not be empty at this point!" ); + assert(pIo && "The pointer may not be empty at this point!"); if( pIo->Good() && pIo->GetStrm() ) { sal_uInt64 nSize = pIo->GetStrm()->TellEnd(); diff --git a/sot/source/sdstor/stgavl.cxx b/sot/source/sdstor/stgavl.cxx index 98a86f3edb96..ac0c5f468024 100644 --- a/sot/source/sdstor/stgavl.cxx +++ b/sot/source/sdstor/stgavl.cxx @@ -59,7 +59,7 @@ sal_Int32 StgAvlNode::Locate sal_Int32 nRes = 0; StgAvlNode* pCur = this; - OSL_ENSURE( pPivot && pParent && pPrev, "The pointers may not be NULL!" ); + assert(pPivot && pParent && pPrev && "The pointers may not be NULL!"); *pParent = *pPrev = nullptr; *pPivot = this; @@ -94,10 +94,11 @@ short StgAvlNode::Adjust( StgAvlNode** pHeavy, StgAvlNode const * pNew ) StgAvlNode* pCur = this; short nDelta; // no traversing - OSL_ENSURE( pHeavy && pNew, "The pointers is not allowed to be NULL!" ); if( pCur == pNew || !pNew ) return m_nBalance; + assert(pHeavy && pNew && "The pointers is not allowed to be NULL!"); + sal_Int32 nRes = Compare( pNew ); if( nRes > 0 ) { diff --git a/svl/source/items/style.cxx b/svl/source/items/style.cxx index 8a2da70793e6..a43e326ad877 100644 --- a/svl/source/items/style.cxx +++ b/svl/source/items/style.cxx @@ -724,7 +724,7 @@ void SfxStyleSheetBasePool::Remove( SfxStyleSheetBase* p ) void SfxStyleSheetBasePool::Insert( SfxStyleSheetBase* p ) { #if OSL_DEBUG_LEVEL > 0 - OSL_ENSURE( p, "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?" ); + assert(p && "svl::SfxStyleSheetBasePool::Insert(), no stylesheet?"); SfxStyleSheetIterator aIter(this, p->GetFamily(), p->GetMask()); SfxStyleSheetBase* pOld = aIter.Find( p->GetName() ); diff --git a/svl/source/misc/strmadpt.cxx b/svl/source/misc/strmadpt.cxx index 7a755d924986..919cb4ab3a45 100644 --- a/svl/source/misc/strmadpt.cxx +++ b/svl/source/misc/strmadpt.cxx @@ -591,6 +591,7 @@ void SvDataPipe_Impl::write(sal_Int8 const * pBuffer, sal_uInt32 nSize) = static_cast< Page * >(std::malloc( sizeof (Page) + m_nPageSize - 1)); + assert(pNew && "Don't handle OOM conditions"); pNew->m_pPrev = m_pWritePage; pNew->m_pNext = m_pWritePage->m_pNext; diff --git a/svl/source/misc/urihelper.cxx b/svl/source/misc/urihelper.cxx index 71ab02491f55..d31a9e8cbe0c 100644 --- a/svl/source/misc/urihelper.cxx +++ b/svl/source/misc/urihelper.cxx @@ -136,7 +136,7 @@ enum Result { Success, GeneralFailure, SpecificFailure }; Result normalizePrefix( css::uno::Reference< css::ucb::XUniversalContentBroker > const & broker, OUString const & uri, OUString * normalized) { - OSL_ASSERT(broker.is() && normalized != nullptr); + assert(broker.is() && normalized != nullptr); css::uno::Reference< css::ucb::XContent > content; try { content = broker->queryContent(broker->createContentIdentifier(uri)); commit fe72e20f865baca9387e5d14327c56b2773d760f Author: Caolán McNamara <caolan.mcnam...@collabora.com> AuthorDate: Tue Apr 30 20:07:06 2024 +0100 Commit: Caolán McNamara <caolan.mcnam...@collabora.com> CommitDate: Wed May 1 09:17:14 2024 +0200 CopyTo is never passed a null argument Change-Id: Ie25e61d6795819a9c432d71fdf478b1a4430c06f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/166940 Tested-by: Caolán McNamara <caolan.mcnam...@collabora.com> Reviewed-by: Caolán McNamara <caolan.mcnam...@collabora.com> diff --git a/include/sot/stg.hxx b/include/sot/stg.hxx index 519b7f701309..66b9c9ac613b 100644 --- a/include/sot/stg.hxx +++ b/include/sot/stg.hxx @@ -86,7 +86,7 @@ public: virtual SotClipboardFormatId GetFormat() = 0; virtual OUString GetUserName() = 0; virtual void FillInfoList( SvStorageInfoList* ) const = 0; - virtual bool CopyTo( BaseStorage* pDestStg ) const = 0; + virtual bool CopyTo( BaseStorage& rDestStg ) const = 0; virtual bool Commit() = 0; virtual bool Revert() = 0; virtual BaseStorageStream* OpenStream( const OUString & rEleName, @@ -173,7 +173,7 @@ public: virtual SotClipboardFormatId GetFormat() override; virtual OUString GetUserName() override; virtual void FillInfoList( SvStorageInfoList* ) const override; - virtual bool CopyTo( BaseStorage* pDestStg ) const override; + virtual bool CopyTo( BaseStorage& rDestStg ) const override; virtual bool Commit() final override; virtual bool Revert() override; virtual BaseStorageStream* OpenStream( const OUString & rEleName, @@ -279,7 +279,7 @@ public: virtual SotClipboardFormatId GetFormat() override; virtual OUString GetUserName() override; virtual void FillInfoList( SvStorageInfoList* ) const override; - virtual bool CopyTo( BaseStorage* pDestStg ) const override; + virtual bool CopyTo( BaseStorage& rDestStg ) const override; virtual bool Commit() final override; virtual bool Revert() override; virtual BaseStorageStream* OpenStream( const OUString & rEleName, diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx index 682aa08f504f..2b3e9a146908 100644 --- a/sot/source/sdstor/stg.cxx +++ b/sot/source/sdstor/stg.cxx @@ -684,7 +684,7 @@ bool Storage::CopyTo( const OUString& rElem, BaseStorage* pDest, const OUString& if( !nTmpErr ) { p2->SetClassId( p1->GetClassId() ); - p1->CopyTo( p2.get() ); + p1->CopyTo( *p2 ); SetError( p1->GetError() ); nTmpErr = p2->GetError(); @@ -730,27 +730,27 @@ bool Storage::CopyTo( const OUString& rElem, BaseStorage* pDest, const OUString& return false; } -bool Storage::CopyTo( BaseStorage* pDest ) const +bool Storage::CopyTo( BaseStorage& rDest ) const { - if( !Validate() || !pDest || !pDest->Validate( true ) || Equals( *pDest ) ) + if( !Validate() || !rDest.Validate( true ) || Equals( rDest ) ) { SetError( SVSTREAM_ACCESS_DENIED ); return false; } Storage* pThis = const_cast<Storage*>(this); - pDest->SetClassId( GetClassId() ); - pDest->SetDirty(); + rDest.SetClassId( GetClassId() ); + rDest.SetDirty(); SvStorageInfoList aList; FillInfoList( &aList ); bool bRes = true; for( size_t i = 0; i < aList.size() && bRes; i++ ) { SvStorageInfo& rInfo = aList[ i ]; - bRes = pThis->CopyTo( rInfo.GetName(), pDest, rInfo.GetName() ); + bRes = pThis->CopyTo( rInfo.GetName(), &rDest, rInfo.GetName() ); } if( !bRes ) - SetError( pDest->GetError() ); - return Good() && pDest->Good(); + SetError( rDest.GetError() ); + return Good() && rDest.Good(); } bool Storage::IsStorage( const OUString& rName ) const diff --git a/sot/source/sdstor/storage.cxx b/sot/source/sdstor/storage.cxx index 937681ee56ef..a91c6f516a0b 100644 --- a/sot/source/sdstor/storage.cxx +++ b/sot/source/sdstor/storage.cxx @@ -461,7 +461,7 @@ bool SotStorage::CopyTo( SotStorage * pDestStg ) { if( m_pOwnStg && pDestStg->m_pOwnStg ) { - m_pOwnStg->CopyTo( pDestStg->m_pOwnStg ); + m_pOwnStg->CopyTo( *pDestStg->m_pOwnStg ); SetError( m_pOwnStg->GetError() ); pDestStg->m_aKey = m_aKey; pDestStg->m_nVersion = m_nVersion; diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index a6f83bb33d77..41e134a345a6 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -2398,7 +2398,7 @@ bool UCBStorage::CopyStorageElement_Impl( UCBStorageElement_Impl const & rElemen pUCBCopy->pImp->m_aUserTypeName ); else pOtherStorage->SetClassId( pStorage->GetClassId() ); - pStorage->CopyTo( pOtherStorage.get() ); + pStorage->CopyTo( *pOtherStorage ); SetError( pStorage->GetError() ); if( pOtherStorage->GetError() ) pDest->SetError( pOtherStorage->GetError() ); @@ -2423,10 +2423,10 @@ UCBStorageElement_Impl* UCBStorage::FindElement_Impl( std::u16string_view rName return nullptr; } -bool UCBStorage::CopyTo( BaseStorage* pDestStg ) const +bool UCBStorage::CopyTo( BaseStorage& rDestStg ) const { - DBG_ASSERT( pDestStg != static_cast<BaseStorage const *>(this), "Self-Copying is not possible!" ); - if ( pDestStg == static_cast<BaseStorage const *>(this) ) + DBG_ASSERT( &rDestStg != static_cast<BaseStorage const *>(this), "Self-Copying is not possible!" ); + if ( &rDestStg == static_cast<BaseStorage const *>(this) ) return false; // perhaps it's also a problem if one storage is a parent of the other ?! @@ -2434,24 +2434,24 @@ bool UCBStorage::CopyTo( BaseStorage* pDestStg ) const // For UCB storages, the class id and the format id may differ, // do passing the class id is not sufficient. - if( dynamic_cast<const UCBStorage *>(pDestStg) != nullptr ) - pDestStg->SetClass( pImp->m_aClassId, pImp->m_nFormat, - pImp->m_aUserTypeName ); + if( dynamic_cast<const UCBStorage *>(&rDestStg) != nullptr ) + rDestStg.SetClass( pImp->m_aClassId, pImp->m_nFormat, + pImp->m_aUserTypeName ); else - pDestStg->SetClassId( GetClassId() ); - pDestStg->SetDirty(); + rDestStg.SetClassId( GetClassId() ); + rDestStg.SetDirty(); bool bRet = true; for ( size_t i = 0; i < pImp->GetChildrenList().size() && bRet; ++i ) { auto& pElement = pImp->GetChildrenList()[ i ]; if ( !pElement->m_bIsRemoved ) - bRet = CopyStorageElement_Impl( *pElement, pDestStg, pElement->m_aName ); + bRet = CopyStorageElement_Impl( *pElement, &rDestStg, pElement->m_aName ); } if( !bRet ) - SetError( pDestStg->GetError() ); - return Good() && pDestStg->Good(); + SetError( rDestStg.GetError() ); + return Good() && rDestStg.Good(); } bool UCBStorage::CopyTo( const OUString& rElemName, BaseStorage* pDest, const OUString& rNew ) diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx index 46b82b2b538e..407c8d508233 100644 --- a/sot/source/unoolestorage/xolesimplestorage.cxx +++ b/sot/source/unoolestorage/xolesimplestorage.cxx @@ -387,7 +387,7 @@ uno::Any SAL_CALL OLESimpleStorage::getByName( const OUString& aName ) throw uno::RuntimeException(); std::unique_ptr<BaseStorage> pNewStor(new Storage( *pStream, false )); - bool bSuccess = ( pStrg->CopyTo( pNewStor.get() ) && pNewStor->Commit() && + bool bSuccess = ( pStrg->CopyTo( *pNewStor ) && pNewStor->Commit() && !pNewStor->GetError() && !pStrg->GetError() ); pNewStor.reset();