diff options
author | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-05 14:03:13 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2019-02-05 14:45:08 +0100 |
commit | 8a7a93b3f24b95bfcffc25e58f9e43c7be4cc1f1 (patch) | |
tree | 651da01917f615025542de018b6c6c92f37a770d /sot/source | |
parent | 5509d639d0b245415f647690619de5a5163ca620 (diff) |
loplugin:flatten in sot
Change-Id: I66ca5113054862f1549a3d7c27da70cf4f5fc308
Reviewed-on: https://gerrit.libreoffice.org/67403
Tested-by: Jenkins
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'sot/source')
-rw-r--r-- | sot/source/sdstor/stg.cxx | 20 | ||||
-rw-r--r-- | sot/source/sdstor/stgdir.cxx | 165 | ||||
-rw-r--r-- | sot/source/sdstor/stgio.cxx | 24 | ||||
-rw-r--r-- | sot/source/sdstor/ucbstorage.cxx | 82 | ||||
-rw-r--r-- | sot/source/unoolestorage/xolesimplestorage.cxx | 34 |
5 files changed, 162 insertions, 163 deletions
diff --git a/sot/source/sdstor/stg.cxx b/sot/source/sdstor/stg.cxx index 435cfa2e80c4..d22bbbe6a465 100644 --- a/sot/source/sdstor/stg.cxx +++ b/sot/source/sdstor/stg.cxx @@ -518,19 +518,19 @@ const OUString& Storage::GetName() const void Storage::FillInfoList( SvStorageInfoList* pList ) const { - if( Validate() && pList ) + if( !(Validate() && pList) ) + return; + + StgIterator aIter( *pEntry ); + StgDirEntry* p = aIter.First(); + while( p ) { - StgIterator aIter( *pEntry ); - StgDirEntry* p = aIter.First(); - while( p ) + if( !p->m_bInvalid ) { - if( !p->m_bInvalid ) - { - SvStorageInfo aInfo( *p ); - pList->push_back( aInfo ); - } - p = aIter.Next(); + SvStorageInfo aInfo( *p ); + pList->push_back( aInfo ); } + p = aIter.Next(); } } diff --git a/sot/source/sdstor/stgdir.cxx b/sot/source/sdstor/stgdir.cxx index df077cf1d911..71a1268cb84d 100644 --- a/sot/source/sdstor/stgdir.cxx +++ b/sot/source/sdstor/stgdir.cxx @@ -148,20 +148,19 @@ void StgDirEntry::DelTemp( bool bForce ) bForce = true; m_pDown->DelTemp( bForce ); } - if( ( bForce || m_bInvalid ) - && ( m_aEntry.GetType() != STG_ROOT ) /* && ( nRefCnt <= 1 ) */ ) + if( !( bForce || m_bInvalid ) || ( m_aEntry.GetType() == STG_ROOT ) ) + return; + + Close(); + if( m_pUp ) { - Close(); - if( m_pUp ) + // this deletes the element if refcnt == 0! + bool bDel = m_nRefCnt == 0; + StgAvlNode::Remove( reinterpret_cast<StgAvlNode**>(&m_pUp->m_pDown), this, bDel ); + if( !bDel ) { - // this deletes the element if refcnt == 0! - bool bDel = m_nRefCnt == 0; - StgAvlNode::Remove( reinterpret_cast<StgAvlNode**>(&m_pUp->m_pDown), this, bDel ); - if( !bDel ) - { - m_pLeft = m_pRight = m_pDown = nullptr; - m_bInvalid = m_bZombie = true; - } + m_pLeft = m_pRight = m_pDown = nullptr; + m_bInvalid = m_bZombie = true; } } } @@ -494,26 +493,26 @@ sal_Int32 StgDirEntry::Write( const void* p, sal_Int32 nLen ) void StgDirEntry::Copy( BaseStorageStream& rDest ) { sal_Int32 n = GetSize(); - if( rDest.SetSize( n ) && n ) - { - sal_uLong Pos = rDest.Tell(); - sal_uInt8 aTempBytes[ 4096 ]; - void* p = static_cast<void*>( aTempBytes ); - Seek( 0 ); - rDest.Seek( 0 ); - while( n ) - { - sal_Int32 nn = n; - if( nn > 4096 ) - nn = 4096; - if( Read( p, nn ) != nn ) - break; - if( sal::static_int_cast<sal_Int32>(rDest.Write( p, nn )) != nn ) - break; - n -= nn; - } - rDest.Seek( Pos ); // ?! Seems to be undocumented ! + if( !(rDest.SetSize( n ) && n) ) + return; + + sal_uLong Pos = rDest.Tell(); + sal_uInt8 aTempBytes[ 4096 ]; + void* p = static_cast<void*>( aTempBytes ); + Seek( 0 ); + rDest.Seek( 0 ); + while( n ) + { + sal_Int32 nn = n; + if( nn > 4096 ) + nn = 4096; + if( Read( p, nn ) != nn ) + break; + if( sal::static_int_cast<sal_Int32>(rDest.Write( p, nn )) != nn ) + break; + n -= nn; } + rDest.Seek( Pos ); // ?! Seems to be undocumented ! } // Commit this entry @@ -733,71 +732,71 @@ StgDirStrm::~StgDirStrm() void StgDirStrm::SetupEntry( sal_Int32 n, StgDirEntry* pUpper ) { void* p = ( n == STG_FREE ) ? nullptr : GetEntry( n, false ); - if( p ) + if( !p ) + return; + + SvStream *pUnderlyingStream = m_rIo.GetStrm(); + sal_uInt64 nUnderlyingStreamSize = pUnderlyingStream->TellEnd(); + + bool bOk(false); + std::unique_ptr<StgDirEntry> pCur(new StgDirEntry( p, STGENTRY_SIZE, nUnderlyingStreamSize, &bOk )); + + if( !bOk ) { - SvStream *pUnderlyingStream = m_rIo.GetStrm(); - sal_uInt64 nUnderlyingStreamSize = pUnderlyingStream->TellEnd(); + m_rIo.SetError( SVSTREAM_GENERALERROR ); + // an error occurred + return; + } - bool bOk(false); - std::unique_ptr<StgDirEntry> pCur(new StgDirEntry( p, STGENTRY_SIZE, nUnderlyingStreamSize, &bOk )); + // better it is + if( !pUpper ) + pCur->m_aEntry.SetType( STG_ROOT ); - if( !bOk ) + sal_Int32 nLeft = pCur->m_aEntry.GetLeaf( STG_LEFT ); + sal_Int32 nRight = pCur->m_aEntry.GetLeaf( STG_RIGHT ); + // substorage? + sal_Int32 nLeaf = STG_FREE; + if( pCur->m_aEntry.GetType() == STG_STORAGE || pCur->m_aEntry.GetType() == STG_ROOT ) + { + nLeaf = pCur->m_aEntry.GetLeaf( STG_CHILD ); + if (nLeaf != STG_FREE && nLeaf == n) { m_rIo.SetError( SVSTREAM_GENERALERROR ); - // an error occurred return; } + } - // better it is - if( !pUpper ) - pCur->m_aEntry.SetType( STG_ROOT ); + if( !(nLeaf != 0 && nLeft != 0 && nRight != 0) ) + return; - sal_Int32 nLeft = pCur->m_aEntry.GetLeaf( STG_LEFT ); - sal_Int32 nRight = pCur->m_aEntry.GetLeaf( STG_RIGHT ); - // substorage? - sal_Int32 nLeaf = STG_FREE; - if( pCur->m_aEntry.GetType() == STG_STORAGE || pCur->m_aEntry.GetType() == STG_ROOT ) + //fdo#41642 + StgDirEntry *pUp = pUpper; + while (pUp) + { + if (pUp->m_aEntry.GetLeaf(STG_CHILD) == nLeaf) { - nLeaf = pCur->m_aEntry.GetLeaf( STG_CHILD ); - if (nLeaf != STG_FREE && nLeaf == n) - { - m_rIo.SetError( SVSTREAM_GENERALERROR ); - return; - } + SAL_WARN("sot", "Leaf node of upper StgDirEntry is same as current StgDirEntry's leaf node. Circular entry chain, discarding link"); + return; } + pUp = pUp->m_pUp; + } - if( nLeaf != 0 && nLeft != 0 && nRight != 0 ) - { - //fdo#41642 - StgDirEntry *pUp = pUpper; - while (pUp) - { - if (pUp->m_aEntry.GetLeaf(STG_CHILD) == nLeaf) - { - SAL_WARN("sot", "Leaf node of upper StgDirEntry is same as current StgDirEntry's leaf node. Circular entry chain, discarding link"); - return; - } - pUp = pUp->m_pUp; - } - - if( StgAvlNode::Insert - ( reinterpret_cast<StgAvlNode**>( pUpper ? &pUpper->m_pDown : &m_pRoot ), pCur.get() ) ) - { - pCur->m_pUp = pUpper; - } - else - { - // bnc#682484: There are some really broken docs out there - // that contain duplicate entries in 'Directory' section - // so don't set the error flag here and just skip those - // (was: rIo.SetError( SVSTREAM_CANNOT_MAKE );) - return; - } - SetupEntry( nLeft, pUpper ); - SetupEntry( nRight, pUpper ); - SetupEntry( nLeaf, pCur.release() ); - } + if( StgAvlNode::Insert + ( reinterpret_cast<StgAvlNode**>( pUpper ? &pUpper->m_pDown : &m_pRoot ), pCur.get() ) ) + { + pCur->m_pUp = pUpper; + } + else + { + // bnc#682484: There are some really broken docs out there + // that contain duplicate entries in 'Directory' section + // so don't set the error flag here and just skip those + // (was: rIo.SetError( SVSTREAM_CANNOT_MAKE );) + return; } + SetupEntry( nLeft, pUpper ); + SetupEntry( nRight, pUpper ); + SetupEntry( nLeaf, pCur.release() ); } // Extend or shrink the directory stream. diff --git a/sot/source/sdstor/stgio.cxx b/sot/source/sdstor/stgio.cxx index e41c3d356ce4..2a82c0731b52 100644 --- a/sot/source/sdstor/stgio.cxx +++ b/sot/source/sdstor/stgio.cxx @@ -105,20 +105,20 @@ void StgIo::SetupStreams() m_pFAT = new StgFATStrm(*this, nFatStrmSize); m_pTOC = new StgDirStrm(*this); - if( !GetError() ) + if( GetError() ) + return; + + StgDirEntry* pRoot = m_pTOC->GetRoot(); + if( pRoot ) { - StgDirEntry* pRoot = m_pTOC->GetRoot(); - if( pRoot ) - { - m_pDataFAT = new StgDataStrm( *this, m_aHdr.GetDataFATStart(), -1 ); - m_pDataStrm = new StgDataStrm( *this, *pRoot ); - m_pDataFAT->SetIncrement( 1 << m_aHdr.GetPageSize() ); - m_pDataStrm->SetIncrement( GetDataPageSize() ); - m_pDataStrm->SetEntry( *pRoot ); - } - else - SetError( SVSTREAM_FILEFORMAT_ERROR ); + m_pDataFAT = new StgDataStrm( *this, m_aHdr.GetDataFATStart(), -1 ); + m_pDataStrm = new StgDataStrm( *this, *pRoot ); + m_pDataFAT->SetIncrement( 1 << m_aHdr.GetPageSize() ); + m_pDataStrm->SetIncrement( GetDataPageSize() ); + m_pDataStrm->SetEntry( *pRoot ); } + else + SetError( SVSTREAM_FILEFORMAT_ERROR ); } // get the logical data page size diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index c4136ade6ddf..6bdcffbf42b3 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -1315,22 +1315,22 @@ void UCBStorageStream::CopyTo( BaseStorageStream* pDestStm ) if( n < 0 ) return; - if( pDestStm->SetSize( n ) && n ) + if( !pDestStm->SetSize( n ) || !n ) + return; + + std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]); + Seek( 0 ); + pDestStm->Seek( 0 ); + while( n ) { - std::unique_ptr<sal_uInt8[]> p(new sal_uInt8[ 4096 ]); - Seek( 0 ); - pDestStm->Seek( 0 ); - while( n ) - { - sal_uInt32 nn = n; - if( nn > 4096 ) - nn = 4096; - if( Read( p.get(), nn ) != nn ) - break; - if( pDestStm->Write( p.get(), nn ) != nn ) - break; - n -= nn; - } + sal_uInt32 nn = n; + if( nn > 4096 ) + nn = 4096; + if( Read( p.get(), nn ) != nn ) + break; + if( pDestStm->Write( p.get(), nn ) != nn ) + break; + n -= nn; } } @@ -1630,23 +1630,23 @@ void UCBStorage_Impl::Init() } } - if ( !m_aContentType.isEmpty() ) - { - // get the clipboard format using the content type - css::datatransfer::DataFlavor aDataFlavor; - aDataFlavor.MimeType = m_aContentType; - m_nFormat = SotExchange::GetFormat( aDataFlavor ); + if ( m_aContentType.isEmpty() ) + return; + + // get the clipboard format using the content type + css::datatransfer::DataFlavor aDataFlavor; + aDataFlavor.MimeType = m_aContentType; + m_nFormat = SotExchange::GetFormat( aDataFlavor ); - // get the ClassId using the clipboard format ( internal table ) - m_aClassId = GetClassId_Impl( m_nFormat ); + // get the ClassId using the clipboard format ( internal table ) + m_aClassId = GetClassId_Impl( m_nFormat ); - // get human presentable name using the clipboard format - SotExchange::GetFormatDataFlavor( m_nFormat, aDataFlavor ); - m_aUserTypeName = aDataFlavor.HumanPresentableName; + // get human presentable name using the clipboard format + SotExchange::GetFormatDataFlavor( m_nFormat, aDataFlavor ); + m_aUserTypeName = aDataFlavor.HumanPresentableName; - if( m_pContent && !m_bIsLinked && m_aClassId != SvGlobalName() ) - ReadContent(); - } + if( m_pContent && !m_bIsLinked && m_aClassId != SvGlobalName() ) + ReadContent(); } void UCBStorage_Impl::CreateContent() @@ -1874,20 +1874,20 @@ void UCBStorage_Impl::SetProps( const Sequence < Sequence < PropertyValue > >& r } } - if ( !m_aContentType.isEmpty() ) - { - // get the clipboard format using the content type - css::datatransfer::DataFlavor aDataFlavor; - aDataFlavor.MimeType = m_aContentType; - m_nFormat = SotExchange::GetFormat( aDataFlavor ); + if ( m_aContentType.isEmpty() ) + return; + + // get the clipboard format using the content type + css::datatransfer::DataFlavor aDataFlavor; + aDataFlavor.MimeType = m_aContentType; + m_nFormat = SotExchange::GetFormat( aDataFlavor ); - // get the ClassId using the clipboard format ( internal table ) - m_aClassId = GetClassId_Impl( m_nFormat ); + // get the ClassId using the clipboard format ( internal table ) + m_aClassId = GetClassId_Impl( m_nFormat ); - // get human presentable name using the clipboard format - SotExchange::GetFormatDataFlavor( m_nFormat, aDataFlavor ); - m_aUserTypeName = aDataFlavor.HumanPresentableName; - } + // get human presentable name using the clipboard format + SotExchange::GetFormatDataFlavor( m_nFormat, aDataFlavor ); + m_aUserTypeName = aDataFlavor.HumanPresentableName; } void UCBStorage_Impl::GetProps( sal_Int32& nProps, Sequence < Sequence < PropertyValue > >& rSequence, const OUString& rPath ) diff --git a/sot/source/unoolestorage/xolesimplestorage.cxx b/sot/source/unoolestorage/xolesimplestorage.cxx index c61b643811f0..1725a990f3d3 100644 --- a/sot/source/unoolestorage/xolesimplestorage.cxx +++ b/sot/source/unoolestorage/xolesimplestorage.cxx @@ -154,27 +154,27 @@ OLESimpleStorage::~OLESimpleStorage() void OLESimpleStorage::UpdateOriginal_Impl() { - if ( !m_bNoTemporaryCopy ) - { - uno::Reference< io::XSeekable > xSeek( m_xStream, uno::UNO_QUERY_THROW ); - xSeek->seek( 0 ); + if ( m_bNoTemporaryCopy ) + return; - uno::Reference< io::XSeekable > xTempSeek( m_xTempStream, uno::UNO_QUERY_THROW ); - sal_Int64 nPos = xTempSeek->getPosition(); - xTempSeek->seek( 0 ); + uno::Reference< io::XSeekable > xSeek( m_xStream, uno::UNO_QUERY_THROW ); + xSeek->seek( 0 ); - uno::Reference< io::XInputStream > xTempInp = m_xTempStream->getInputStream(); - uno::Reference< io::XOutputStream > xOutputStream = m_xStream->getOutputStream(); - if ( !xTempInp.is() || !xOutputStream.is() ) - throw uno::RuntimeException(); + uno::Reference< io::XSeekable > xTempSeek( m_xTempStream, uno::UNO_QUERY_THROW ); + sal_Int64 nPos = xTempSeek->getPosition(); + xTempSeek->seek( 0 ); - uno::Reference< io::XTruncate > xTrunc( xOutputStream, uno::UNO_QUERY_THROW ); - xTrunc->truncate(); + uno::Reference< io::XInputStream > xTempInp = m_xTempStream->getInputStream(); + uno::Reference< io::XOutputStream > xOutputStream = m_xStream->getOutputStream(); + if ( !xTempInp.is() || !xOutputStream.is() ) + throw uno::RuntimeException(); - ::comphelper::OStorageHelper::CopyInputToOutput( xTempInp, xOutputStream ); - xOutputStream->flush(); - xTempSeek->seek( nPos ); - } + uno::Reference< io::XTruncate > xTrunc( xOutputStream, uno::UNO_QUERY_THROW ); + xTrunc->truncate(); + + ::comphelper::OStorageHelper::CopyInputToOutput( xTempInp, xOutputStream ); + xOutputStream->flush(); + xTempSeek->seek( nPos ); } |