Kaydet (Commit) 8a7a93b3 authored tarafından Noel Grandin's avatar Noel Grandin

loplugin:flatten in sot

Change-Id: I66ca5113054862f1549a3d7c27da70cf4f5fc308
Reviewed-on: https://gerrit.libreoffice.org/67403
Tested-by: Jenkins
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 5509d639
......@@ -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();
}
}
......
......@@ -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.
......
......@@ -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
......
......@@ -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 )
......
......@@ -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 );
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment