From 0e4c542f7a862e681baf25f042bc3a928c14004f Mon Sep 17 00:00:00 2001 From: Arkadiy Illarionov Date: Fri, 3 May 2019 22:11:02 +0300 Subject: Use hasElements to check Sequence emptiness in [l-r]* Similar to clang-tidy readability-container-size-empty Change-Id: Idd67f332b04857a39df26bad1733aae21236f105 Reviewed-on: https://gerrit.libreoffice.org/71764 Tested-by: Jenkins Reviewed-by: Michael Stahl --- package/source/xstor/owriteablestream.cxx | 8 ++++---- package/source/xstor/xstorage.cxx | 2 +- package/source/zipapi/XBufferedThreadedStream.cxx | 2 +- package/source/zipapi/XUnbufferedStream.cxx | 8 ++++---- package/source/zipapi/ZipFile.cxx | 20 ++++++++++---------- package/source/zipapi/ZipOutputEntry.cxx | 2 +- package/source/zippackage/ZipPackage.cxx | 16 ++++++++-------- package/source/zippackage/ZipPackageFolder.cxx | 2 +- package/source/zippackage/ZipPackageStream.cxx | 16 ++++++++-------- package/source/zippackage/zipfileaccess.cxx | 2 +- 10 files changed, 39 insertions(+), 39 deletions(-) (limited to 'package') diff --git a/package/source/xstor/owriteablestream.cxx b/package/source/xstor/owriteablestream.cxx index 213c53efaf49..b9ea32c3ed70 100644 --- a/package/source/xstor/owriteablestream.cxx +++ b/package/source/xstor/owriteablestream.cxx @@ -89,7 +89,7 @@ bool PackageEncryptionDatasEqual( const ::comphelper::SequenceAsHashMap& aHash1, ++aIter ) { uno::Sequence< sal_Int8 > aKey1; - bResult = ( ( aIter->second >>= aKey1 ) && aKey1.getLength() ); + bResult = ( ( aIter->second >>= aKey1 ) && aKey1.hasElements() ); if ( bResult ) { uno::Sequence< sal_Int8 > aKey2 = aHash2.getUnpackedValueOrDefault( aIter->first, uno::Sequence< sal_Int8 >() ); @@ -401,7 +401,7 @@ bool OWriteStream_Impl::IsEncrypted() // That means that if it is intended to use common storage key // it is already has no encryption but is marked to be stored // encrypted and the key is empty. - if ( !bWasEncr && bToBeEncr && !aKey.getLength() ) + if ( !bWasEncr && bToBeEncr && !aKey.hasElements() ) { // the stream is intended to use common storage password m_bUseCommonEncryption = true; @@ -926,7 +926,7 @@ void OWriteStream_Impl::Revert() uno::Sequence< beans::PropertyValue > const & OWriteStream_Impl::GetStreamProperties() { - if ( !m_aProps.getLength() ) + if ( !m_aProps.hasElements() ) m_aProps = ReadPackageStreamProperties(); return m_aProps; @@ -1551,7 +1551,7 @@ void OWriteStream_Impl::CommitStreamRelInfo( const uno::Reference< embed::XStora if ( m_nRelInfoStatus == RELINFO_CHANGED ) { - if ( m_aNewRelInfo.getLength() ) + if ( m_aNewRelInfo.hasElements() ) { uno::Reference< io::XStream > xRelsStream = xRelStorage->openStreamElement( aNewRelStreamName, diff --git a/package/source/xstor/xstorage.cxx b/package/source/xstor/xstorage.cxx index 95233f787b45..b10e4fafa5ef 100644 --- a/package/source/xstor/xstorage.cxx +++ b/package/source/xstor/xstorage.cxx @@ -5518,7 +5518,7 @@ uno::Reference< embed::XExtendedStorageStream > SAL_CALL OStorage::openEncrypted if ( aStreamPath.isEmpty() || !::comphelper::OStorageHelper::IsValidZipEntryFileName( aStreamPath, true ) ) throw lang::IllegalArgumentException( THROW_WHERE "Unexpected entry name syntax.", uno::Reference< uno::XInterface >(), 1 ); - if ( !aEncryptionData.getLength() ) + if ( !aEncryptionData.hasElements() ) throw lang::IllegalArgumentException( THROW_WHERE, uno::Reference< uno::XInterface >(), 3 ); if ( !( m_pImpl->m_nStorageMode & embed::ElementModes::WRITE ) diff --git a/package/source/zipapi/XBufferedThreadedStream.cxx b/package/source/zipapi/XBufferedThreadedStream.cxx index e40613d4b66e..6bc7da7fa173 100644 --- a/package/source/zipapi/XBufferedThreadedStream.cxx +++ b/package/source/zipapi/XBufferedThreadedStream.cxx @@ -143,7 +143,7 @@ sal_Int32 SAL_CALL XBufferedThreadedStream::readBytes( Sequence< sal_Int8 >& rDa while( nPendingBytes ) { const Buffer &pBuffer = getNextBlock(); - if( pBuffer.getLength() <= 0 ) + if( !pBuffer.hasElements() ) { rData.realloc( nAvailableSize - nPendingBytes ); return nAvailableSize - nPendingBytes; diff --git a/package/source/zipapi/XUnbufferedStream.cxx b/package/source/zipapi/XUnbufferedStream.cxx index 8c0b97d1367b..82b6981f4378 100644 --- a/package/source/zipapi/XUnbufferedStream.cxx +++ b/package/source/zipapi/XUnbufferedStream.cxx @@ -81,10 +81,10 @@ XUnbufferedStream::XUnbufferedStream( if (mnZipSize < 0) throw ZipIOException("The stream seems to be broken!"); - bool bHaveEncryptData = rData.is() && rData->m_aInitVector.getLength() && - ((rData->m_aSalt.getLength() && rData->m_nIterationCount != 0) + bool bHaveEncryptData = rData.is() && rData->m_aInitVector.hasElements() && + ((rData->m_aSalt.hasElements() && rData->m_nIterationCount != 0) || - rData->m_aKey.getLength()); + rData->m_aKey.hasElements()); bool bMustDecrypt = nStreamMode == UNBUFF_STREAM_DATA && bHaveEncryptData && bIsEncrypted; if ( bMustDecrypt ) @@ -268,7 +268,7 @@ sal_Int32 SAL_CALL XUnbufferedStream::readBytes( Sequence< sal_Int8 >& aData, sa if ( mnZipCurrent == mnZipEnd ) { uno::Sequence< sal_Int8 > aSuffix = m_xCipherContext->finalizeCipherContextAndDispose(); - if ( aSuffix.getLength() ) + if ( aSuffix.hasElements() ) { sal_Int32 nOldLen = maCompBuffer.getLength(); maCompBuffer.realloc( nOldLen + aSuffix.getLength() ); diff --git a/package/source/zipapi/ZipFile.cxx b/package/source/zipapi/ZipFile.cxx index f37f38c03e62..af90d6b1ef1a 100644 --- a/package/source/zipapi/ZipFile.cxx +++ b/package/source/zipapi/ZipFile.cxx @@ -397,7 +397,7 @@ uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const rtl::R if ( !rData.is() ) throw ZipIOException("Encrypted stream without encryption data!" ); - if ( !rData->m_aKey.getLength() ) + if ( !rData->m_aKey.hasElements() ) throw packages::WrongPasswordException(THROW_WHERE ); uno::Reference< XSeekable > xSeek( xStream, UNO_QUERY ); @@ -406,8 +406,8 @@ uno::Reference< XInputStream > ZipFile::StaticGetDataFromRawStream( const rtl::R // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!" ); - if ( rData->m_aDigest.getLength() ) + OSL_ENSURE( rData->m_aDigest.hasElements(), "Can't detect password correctness without digest!" ); + if ( rData->m_aDigest.hasElements() ) { sal_Int32 nSize = sal::static_int_cast< sal_Int32 >( xSeek->getLength() ); if ( nSize > n_ConstDigestLength + 32 ) @@ -446,7 +446,7 @@ void CheckSequence( const uno::Sequence< sal_Int8 >& aSequence ) bool ZipFile::StaticHasValidPassword( const uno::Reference< uno::XComponentContext >& rxContext, const Sequence< sal_Int8 > &aReadBuffer, const ::rtl::Reference< EncryptionData > &rData ) { - if ( !rData.is() || !rData->m_aKey.getLength() ) + if ( !rData.is() || !rData->m_aKey.hasElements() ) return false; bool bRet = false; @@ -466,7 +466,7 @@ bool ZipFile::StaticHasValidPassword( const uno::Reference< uno::XComponentConte // it is no problem, actually this is why we read 32 additional bytes ( two of maximal possible encryption blocks ) } - if ( aDecryptBuffer2.getLength() ) + if ( aDecryptBuffer2.hasElements() ) { sal_Int32 nOldLen = aDecryptBuffer.getLength(); aDecryptBuffer.realloc( nOldLen + aDecryptBuffer2.getLength() ); @@ -483,7 +483,7 @@ bool ZipFile::StaticHasValidPassword( const uno::Reference< uno::XComponentConte aDigestSeq = xDigestContext->finalizeDigestAndDispose(); // If we don't have a digest, then we have to assume that the password is correct - if ( rData->m_aDigest.getLength() != 0 && + if ( rData->m_aDigest.hasElements() && ( aDigestSeq.getLength() != rData->m_aDigest.getLength() || 0 != memcmp ( aDigestSeq.getConstArray(), rData->m_aDigest.getConstArray(), @@ -502,7 +502,7 @@ bool ZipFile::hasValidPassword ( ZipEntry const & rEntry, const ::rtl::Reference ::osl::MutexGuard aGuard( m_aMutexHolder->GetMutex() ); bool bRet = false; - if ( rData.is() && rData->m_aKey.getLength() ) + if ( rData.is() && rData->m_aKey.hasElements() ) { css::uno::Reference < css::io::XSeekable > xSeek(xStream, UNO_QUERY_THROW); xSeek->seek( rEntry.nOffset ); @@ -667,7 +667,7 @@ uno::Reference< XInputStream > ZipFile::getInputStream( ZipEntry& rEntry, // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - if ( bIsEncrypted && rData.is() && rData->m_aDigest.getLength() ) + if ( bIsEncrypted && rData.is() && rData->m_aDigest.hasElements() ) bNeedRawStream = !hasValidPassword ( rEntry, rData ); return createStreamForZipEntry ( aMutexHolder, @@ -699,8 +699,8 @@ uno::Reference< XInputStream > ZipFile::getDataStream( ZipEntry& rEntry, // if we have a digest, then this file is an encrypted one and we should // check if we can decrypt it or not - OSL_ENSURE( rData->m_aDigest.getLength(), "Can't detect password correctness without digest!" ); - if ( rData->m_aDigest.getLength() && !hasValidPassword ( rEntry, rData ) ) + OSL_ENSURE( rData->m_aDigest.hasElements(), "Can't detect password correctness without digest!" ); + if ( rData->m_aDigest.hasElements() && !hasValidPassword ( rEntry, rData ) ) throw packages::WrongPasswordException(THROW_WHERE ); } else diff --git a/package/source/zipapi/ZipOutputEntry.cxx b/package/source/zipapi/ZipOutputEntry.cxx index 3fa6e2792752..2b1447bd3246 100644 --- a/package/source/zipapi/ZipOutputEntry.cxx +++ b/package/source/zipapi/ZipOutputEntry.cxx @@ -229,7 +229,7 @@ void ZipOutputEntry::doDeflate() { // FIXME64: sequence not 64bit safe. uno::Sequence< sal_Int8 > aEncryptionBuffer = m_xCipherContext->finalizeCipherContextAndDispose(); - if ( aEncryptionBuffer.getLength() ) + if ( aEncryptionBuffer.hasElements() ) { m_xOutStream->writeBytes( aEncryptionBuffer ); diff --git a/package/source/zippackage/ZipPackage.cxx b/package/source/zippackage/ZipPackage.cxx index 42c78532a2db..5a715d3ccfda 100644 --- a/package/source/zippackage/ZipPackage.cxx +++ b/package/source/zippackage/ZipPackage.cxx @@ -600,7 +600,7 @@ void SAL_CALL ZipPackage::initialize( const uno::Sequence< Any >& aArguments ) { beans::NamedValue aNamedValue; - if ( aArguments.getLength() ) + if ( aArguments.hasElements() ) { bool bHaveZipFile = true; @@ -1000,7 +1000,7 @@ uno::Reference< XInterface > SAL_CALL ZipPackage::createInstanceWithArguments( c { bool bArg = false; uno::Reference < XInterface > xRef; - if ( aArguments.getLength() ) + if ( aArguments.hasElements() ) aArguments[0] >>= bArg; if ( bArg ) xRef = *new ZipPackageFolder( m_xContext, m_nFormat, m_bAllowRemoveOnInsert ); @@ -1633,7 +1633,7 @@ const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey() { uno::Sequence< sal_Int8 > aResult; - if ( m_aStorageEncryptionKeys.getLength() ) + if ( m_aStorageEncryptionKeys.hasElements() ) { OUString aNameToFind; if ( m_nStartKeyGenerationID == xml::crypto::DigestID::SHA256 ) @@ -1649,7 +1649,7 @@ const uno::Sequence< sal_Int8 > ZipPackage::GetEncryptionKey() // empty keys are not allowed here // so it is not important whether there is no key, or the key is empty, it is an error - if ( !aResult.getLength() ) + if ( !aResult.hasElements() ) throw uno::RuntimeException(THROW_WHERE "No expected key is provided!" ); } else @@ -1753,10 +1753,10 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const // because of this support the storage has to operate with more than one key dependent on storage generation algorithm; // when this support is removed, the storage will get only one key from outside uno::Sequence< beans::NamedValue > aKeys; - if ( !( aValue >>= aKeys ) || ( aKeys.getLength() && aKeys.getLength() < 1 ) ) + if ( !( aValue >>= aKeys ) ) throw IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 2 ); - if ( aKeys.getLength() ) + if ( aKeys.hasElements() ) { bool bHasSHA256 = false; bool bHasSHA1 = false; @@ -1778,7 +1778,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const else if ( aPropertyName == ENCRYPTION_ALGORITHMS_PROPERTY ) { uno::Sequence< beans::NamedValue > aAlgorithms; - if ( m_pZipFile || !( aValue >>= aAlgorithms ) || aAlgorithms.getLength() == 0 ) + if ( m_pZipFile || !( aValue >>= aAlgorithms ) || !aAlgorithms.hasElements() ) { // the algorithms can not be changed if the file has a persistence based on the algorithms ( m_pZipFile ) throw IllegalArgumentException(THROW_WHERE "unexpected algorithms list is provided.", uno::Reference< uno::XInterface >(), 2 ); @@ -1823,7 +1823,7 @@ void SAL_CALL ZipPackage::setPropertyValue( const OUString& aPropertyName, const else if ( aPropertyName == ENCRYPTION_GPG_PROPERTIES ) { uno::Sequence< uno::Sequence< beans::NamedValue > > aGpgProps; - if ( !( aValue >>= aGpgProps ) || aGpgProps.getLength() == 0 ) + if ( !( aValue >>= aGpgProps ) || !aGpgProps.hasElements() ) { throw IllegalArgumentException(THROW_WHERE "unexpected Gpg properties are provided.", uno::Reference< uno::XInterface >(), 2 ); } diff --git a/package/source/zippackage/ZipPackageFolder.cxx b/package/source/zippackage/ZipPackageFolder.cxx index c42fdef45ac8..1aaaedcd3d89 100644 --- a/package/source/zippackage/ZipPackageFolder.cxx +++ b/package/source/zippackage/ZipPackageFolder.cxx @@ -273,7 +273,7 @@ bool ZipPackageFolder::saveChild( saveContents( sTempName, rManList, rZipOut, rEncryptionKey, nPBKDF2IterationCount, rRandomPool); // folder can have a mediatype only in package format - if ( aPropSet.getLength() && ( m_nFormat == embed::StorageFormats::PACKAGE ) ) + if ( aPropSet.hasElements() && ( m_nFormat == embed::StorageFormats::PACKAGE ) ) rManList.push_back( aPropSet ); return true; diff --git a/package/source/zippackage/ZipPackageStream.cxx b/package/source/zippackage/ZipPackageStream.cxx index 3d6f5b432986..db58a2892c33 100644 --- a/package/source/zippackage/ZipPackageStream.cxx +++ b/package/source/zippackage/ZipPackageStream.cxx @@ -220,7 +220,7 @@ uno::Sequence ZipPackageStream::GetEncryptionKey(Bugs const bugs) sal_Int32 nKeyGenID = GetStartKeyGenID(); bool const bUseWinEncoding = (bugs == Bugs::WinEncodingWrongSHA1 || m_bUseWinEncoding); - if ( m_bHaveOwnKey && m_aStorageEncryptionKeys.getLength() ) + if ( m_bHaveOwnKey && m_aStorageEncryptionKeys.hasElements() ) { OUString aNameToFind; if ( nKeyGenID == xml::crypto::DigestID::SHA256 ) @@ -242,13 +242,13 @@ uno::Sequence ZipPackageStream::GetEncryptionKey(Bugs const bugs) // empty keys are not allowed here // so it is not important whether there is no key, or the key is empty, it is an error - if ( !aResult.getLength() ) + if ( !aResult.hasElements() ) throw uno::RuntimeException(THROW_WHERE "No expected key is provided!" ); } else aResult = m_aEncryptionKey; - if ( !aResult.getLength() || !m_bHaveOwnKey ) + if ( !aResult.hasElements() || !m_bHaveOwnKey ) aResult = m_rZipPackage.GetEncryptionKey(); return aResult; @@ -271,7 +271,7 @@ uno::Reference< io::XInputStream > ZipPackageStream::TryToGetRawFromDataStream( if ( m_bToBeEncrypted ) { aKey = GetEncryptionKey(); - if ( !aKey.getLength() ) + if ( !aKey.hasElements() ) throw packages::NoEncryptionException(THROW_WHERE ); } @@ -538,7 +538,7 @@ bool ZipPackageStream::saveChild( pTempEntry->sPath = rPath; pTempEntry->nPathLen = static_cast( OUStringToOString( pTempEntry->sPath, RTL_TEXTENCODING_UTF8 ).getLength() ); - const bool bToBeEncrypted = m_bToBeEncrypted && (rEncryptionKey.getLength() || m_bHaveOwnKey); + const bool bToBeEncrypted = m_bToBeEncrypted && (rEncryptionKey.hasElements() || m_bHaveOwnKey); const bool bToBeCompressed = bToBeEncrypted || m_bToBeCompressed; aPropSet[PKG_MNFST_MEDIATYPE].Name = sMediaTypeProperty; @@ -880,7 +880,7 @@ bool ZipPackageStream::saveChild( if (bSuccess && !bParallelDeflate) successfullyWritten(pTempEntry); - if ( aPropSet.getLength() + if ( aPropSet.hasElements() && ( m_nFormat == embed::StorageFormats::PACKAGE || m_nFormat == embed::StorageFormats::OFOPXML ) ) rManList.push_back( aPropSet ); @@ -1243,7 +1243,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, aNewKey = aSequence; } - if ( aNewKey.getLength() ) + if ( aNewKey.hasElements() ) { if ( !m_xBaseEncryptionData.is() ) m_xBaseEncryptionData = new BaseEncryptionData; @@ -1275,7 +1275,7 @@ void SAL_CALL ZipPackageStream::setPropertyValue( const OUString& aPropertyName, 2 ); } - if ( aKeys.getLength() ) + if ( aKeys.hasElements() ) { if ( !m_xBaseEncryptionData.is() ) m_xBaseEncryptionData = new BaseEncryptionData; diff --git a/package/source/zippackage/zipfileaccess.cxx b/package/source/zippackage/zipfileaccess.cxx index 01252838e110..45079fdbaec3 100644 --- a/package/source/zippackage/zipfileaccess.cxx +++ b/package/source/zippackage/zipfileaccess.cxx @@ -173,7 +173,7 @@ void SAL_CALL OZipFileAccess::initialize( const uno::Sequence< uno::Any >& aArgu if ( m_pZipFile ) throw uno::RuntimeException(THROW_WHERE ); // initialization is allowed only one time - if ( !aArguments.getLength() ) + if ( !aArguments.hasElements() ) throw lang::IllegalArgumentException(THROW_WHERE, uno::Reference< uno::XInterface >(), 1 ); OSL_ENSURE( aArguments.getLength() == 1, "Too many arguments are provided, only the first one will be used!" ); -- cgit