binaryurp/source/reader.cxx | 3 ++- chart2/source/tools/ObjectIdentifier.cxx | 4 ++-- dbaccess/source/core/api/RowSetCache.cxx | 2 +- dbaccess/source/ui/dlg/CollectionView.cxx | 5 +++-- reportdesign/source/core/misc/conditionalexpression.cxx | 3 ++- sc/source/core/data/dpobject.cxx | 3 ++- sc/source/core/data/dpoutput.cxx | 2 +- sc/source/ui/vba/vbarange.cxx | 5 +++-- sot/source/sdstor/ucbstorage.cxx | 3 ++- svx/source/fmcomp/fmgridif.cxx | 3 ++- sw/source/core/layout/dbg_lay.cxx | 3 ++- xmloff/source/chart/SchXMLTableContext.cxx | 2 +- 12 files changed, 23 insertions(+), 15 deletions(-)
New commits: commit e89e3a8b5a7639f14833d066e8a6c445dca97cc0 Author: Stephan Bergmann <sberg...@redhat.com> AuthorDate: Wed Jun 1 09:09:46 2022 +0200 Commit: Stephan Bergmann <sberg...@redhat.com> CommitDate: Wed Jun 1 10:49:20 2022 +0200 The return value of those getLength functions is guaranteed to be non-negative ...so use o3tl::make_unsigned when comparing it against an expression of unsigned integer type, instead of casting that expression to a signed type Change-Id: Ic47c6d96919b2aba2d16ce6d1a2a8e4c5761a480 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/135219 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sberg...@redhat.com> diff --git a/binaryurp/source/reader.cxx b/binaryurp/source/reader.cxx index 91f2e51a0f25..7cabbd41c8a1 100644 --- a/binaryurp/source/reader.cxx +++ b/binaryurp/source/reader.cxx @@ -35,6 +35,7 @@ #include <com/sun/star/uno/XCurrentContext.hpp> #include <com/sun/star/uno/XInterface.hpp> #include <cppu/unotype.hxx> +#include <o3tl/safeint.hxx> #include <rtl/byteseq.h> #include <rtl/ustring.hxx> #include <sal/log.hxx> @@ -74,7 +75,7 @@ css::uno::Sequence< sal_Int8 > read( throw css::io::IOException( "binaryurp::Reader: premature end of input"); } - assert(buf.getLength() == static_cast< sal_Int32 >(size)); + assert(o3tl::make_unsigned(buf.getLength()) == size); return buf; } diff --git a/chart2/source/tools/ObjectIdentifier.cxx b/chart2/source/tools/ObjectIdentifier.cxx index a8622e3ff4c4..6b8b9e2809cc 100644 --- a/chart2/source/tools/ObjectIdentifier.cxx +++ b/chart2/source/tools/ObjectIdentifier.cxx @@ -439,7 +439,7 @@ OUString ObjectIdentifier::createClassifiedIdentifierForParticles( OUStringBuffer aRet( m_aProtocol ); aRet.append( lcl_createClassificationStringForType( eObjectType, rDragMethodServiceName, rDragParameterString )); - if(aRet.getLength() > static_cast<sal_Int32>(std::size(m_aProtocol)-1)) + if(o3tl::make_unsigned(aRet.getLength()) >= std::size(m_aProtocol)) aRet.append("/"); if(!rParentParticle.empty()) @@ -563,7 +563,7 @@ OUString ObjectIdentifier::createClassifiedIdentifierWithParent( OUStringBuffer aRet( m_aProtocol ); aRet.append( lcl_createClassificationStringForType( eObjectType, rDragMethodServiceName, rDragParameterString )); - if(aRet.getLength() > static_cast<sal_Int32>(std::size(m_aProtocol)-1)) + if(o3tl::make_unsigned(aRet.getLength()) >= std::size(m_aProtocol)) aRet.append("/"); aRet.append(rParentPartical); if(!rParentPartical.empty()) diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx index 46b2cea95a02..8a23d6624180 100644 --- a/dbaccess/source/core/api/RowSetCache.cxx +++ b/dbaccess/source/core/api/RowSetCache.cxx @@ -207,7 +207,7 @@ ORowSetCache::ORowSetCache(const Reference< XResultSet >& _xRs, Reference<XDatabaseMetaData> xMeta = xConnection->getMetaData(); SelectColumnsMetaData aColumnNames(xMeta.is() && xMeta->supportsMixedCaseQuotedIdentifiers()); ::dbaccess::getColumnPositions(xSelColumns,xPrimaryKeyColumns->getElementNames(),aUpdateTableName,aColumnNames); - bAllKeysFound = !aColumnNames.empty() && sal_Int32(aColumnNames.size()) == xPrimaryKeyColumns->getElementNames().getLength(); + bAllKeysFound = !aColumnNames.empty() && aColumnNames.size() == o3tl::make_unsigned(xPrimaryKeyColumns->getElementNames().getLength()); } } } diff --git a/dbaccess/source/ui/dlg/CollectionView.cxx b/dbaccess/source/ui/dlg/CollectionView.cxx index d8a6d2621fe3..2e02fda505e0 100644 --- a/dbaccess/source/ui/dlg/CollectionView.cxx +++ b/dbaccess/source/ui/dlg/CollectionView.cxx @@ -26,6 +26,7 @@ #include <cppuhelper/exc_hlp.hxx> #include <com/sun/star/container/XChild.hpp> #include <com/sun/star/container/XNameContainer.hpp> +#include <o3tl/safeint.hxx> #include <vcl/svapp.hxx> #include <vcl/weld.hxx> #include <UITools.hxx> @@ -256,9 +257,9 @@ void OCollectionView::initCurrentPath() static const char s_sReportsCID[] = "private:reports"; m_bCreateForm = s_sFormsCID == sCID; OUString sPath("/"); - if ( m_bCreateForm && sCID.getLength() != static_cast<sal_Int32>(strlen(s_sFormsCID))) + if ( m_bCreateForm && o3tl::make_unsigned(sCID.getLength()) != strlen(s_sFormsCID)) sPath = sCID.copy(strlen(s_sFormsCID)); - else if ( !m_bCreateForm && sCID.getLength() != static_cast<sal_Int32>(strlen(s_sReportsCID)) ) + else if ( !m_bCreateForm && o3tl::make_unsigned(sCID.getLength()) != strlen(s_sReportsCID) ) sPath = sCID.copy(strlen(s_sReportsCID) - 2); m_xFTCurrentPath->set_label(sPath); diff --git a/reportdesign/source/core/misc/conditionalexpression.cxx b/reportdesign/source/core/misc/conditionalexpression.cxx index d8f37efc9578..0fe6dbb40702 100644 --- a/reportdesign/source/core/misc/conditionalexpression.cxx +++ b/reportdesign/source/core/misc/conditionalexpression.cxx @@ -19,6 +19,7 @@ #include <conditionalexpression.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> @@ -108,7 +109,7 @@ namespace rptui bool bHaveRHS( nRHSIndex != -1 ); sal_Int32 nRightMostIndex( bHaveRHS ? nRHSIndex : nLHSIndex ); const std::u16string_view sMatchExprPart3( sMatchExpression.subView( nRightMostIndex + 2 ) ); - if ( _rExpression.getLength() < static_cast<sal_Int32>(sMatchExprPart3.size()) ) + if ( o3tl::make_unsigned(_rExpression.getLength()) < sMatchExprPart3.size() ) // the expression is not even long enough to hold the right-most part of the match expression return false; const std::u16string_view sExprPart3( _rExpression.subView( _rExpression.getLength() - sMatchExprPart3.size() ) ); diff --git a/sc/source/core/data/dpobject.cxx b/sc/source/core/data/dpobject.cxx index b74fc5d7dfe5..e6b312e51add 100644 --- a/sc/source/core/data/dpobject.cxx +++ b/sc/source/core/data/dpobject.cxx @@ -68,6 +68,7 @@ #include <comphelper/processfactory.hxx> #include <comphelper/string.hxx> #include <comphelper/types.hxx> +#include <o3tl/safeint.hxx> #include <sal/macros.h> #include <svl/numformat.hxx> #include <tools/diagnose_ex.h> @@ -1393,7 +1394,7 @@ double ScDPObject::GetPivotData(const OUString& rDataFieldName, std::vector<shee aFiltersRange[i] = rFilters[i]; uno::Sequence<double> aRes = xDPResults->getFilteredResults(aFilters); - if (static_cast<sal_Int32>(nDataIndex) >= aRes.getLength()) + if (nDataIndex >= o3tl::make_unsigned(aRes.getLength())) return std::numeric_limits<double>::quiet_NaN(); return aRes[nDataIndex]; diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx index c15f9b6e848f..cf08913ac502 100644 --- a/sc/source/core/data/dpoutput.cxx +++ b/sc/source/core/data/dpoutput.cxx @@ -493,7 +493,7 @@ uno::Sequence<sheet::MemberResult> getVisiblePageMembersAsResults( const uno::Re } } - if (aNames.getLength() == static_cast<sal_Int32>(aRes.size())) + if (o3tl::make_unsigned(aNames.getLength()) == aRes.size()) // All members are visible. Return empty result. return uno::Sequence<sheet::MemberResult>(); diff --git a/sc/source/ui/vba/vbarange.cxx b/sc/source/ui/vba/vbarange.cxx index 6774d8361f61..5a6c1f2f18b7 100644 --- a/sc/source/ui/vba/vbarange.cxx +++ b/sc/source/ui/vba/vbarange.cxx @@ -22,6 +22,7 @@ #include <comphelper/types.hxx> #include <cppuhelper/exc_hlp.hxx> #include <o3tl/any.hxx> +#include <o3tl/safeint.hxx> #include <o3tl/unit_conversion.hxx> #include <rtl/math.hxx> #include <tools/diagnose_ex.h> @@ -4336,7 +4337,7 @@ static void lcl_setTableFieldsFromCriteria( OUString& sCriteria1, const uno::Ref // [>|>=|<=|...]searchtext for GREATER_value, GREATER_EQUAL_value etc. if ( sCriteria1.startsWith( EQUALS ) ) { - if ( sCriteria1.getLength() == static_cast<sal_Int32>(strlen(EQUALS)) ) + if ( o3tl::make_unsigned(sCriteria1.getLength()) == strlen(EQUALS) ) rFilterField.Operator = sheet::FilterOperator2::EMPTY; else { @@ -4351,7 +4352,7 @@ static void lcl_setTableFieldsFromCriteria( OUString& sCriteria1, const uno::Ref } else if ( sCriteria1.startsWith( NOTEQUALS ) ) { - if ( sCriteria1.getLength() == static_cast<sal_Int32>(strlen(NOTEQUALS)) ) + if ( o3tl::make_unsigned(sCriteria1.getLength()) == strlen(NOTEQUALS) ) rFilterField.Operator = sheet::FilterOperator2::NOT_EMPTY; else { diff --git a/sot/source/sdstor/ucbstorage.cxx b/sot/source/sdstor/ucbstorage.cxx index f478173d5dc5..4e2dc1a2a6ea 100644 --- a/sot/source/sdstor/ucbstorage.cxx +++ b/sot/source/sdstor/ucbstorage.cxx @@ -43,6 +43,7 @@ #include <memory> #include <optional> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <osl/file.hxx> #include <sal/log.hxx> @@ -157,7 +158,7 @@ sal_Int32 SAL_CALL FileStreamWrapper_Impl::readBytes(Sequence< sal_Int8 >& aData checkError(); // if read characters < MaxLength, adjust sequence - if (static_cast<sal_Int32>(nRead) < aData.getLength()) + if (nRead < o3tl::make_unsigned(aData.getLength())) aData.realloc( nRead ); return nRead; diff --git a/svx/source/fmcomp/fmgridif.cxx b/svx/source/fmcomp/fmgridif.cxx index 5ff7ddccae7d..bce6303d291f 100644 --- a/svx/source/fmcomp/fmgridif.cxx +++ b/svx/source/fmcomp/fmgridif.cxx @@ -55,6 +55,7 @@ #include <comphelper/types.hxx> #include <cppuhelper/supportsservice.hxx> #include <cppuhelper/queryinterface.hxx> +#include <o3tl/safeint.hxx> #include <vcl/unohelp.hxx> #include <vcl/svapp.hxx> #include <tools/debug.hxx> @@ -2784,7 +2785,7 @@ IMPL_LINK(FmXGridPeer, OnExecuteGridSlot, DbGridControlNavigationBarState, nSlot const std::vector<DbGridControlNavigationBarState>& aSlots = getSupportedGridSlots(); - DBG_ASSERT(static_cast<sal_Int32>(aSlots.size()) == aUrls.getLength(), "FmXGridPeer::OnExecuteGridSlot : inconsistent data returned by getSupportedURLs/getSupportedGridSlots!"); + DBG_ASSERT(aSlots.size() == o3tl::make_unsigned(aUrls.getLength()), "FmXGridPeer::OnExecuteGridSlot : inconsistent data returned by getSupportedURLs/getSupportedGridSlots!"); for (size_t i=0; i<aSlots.size(); ++i, ++pUrls) { diff --git a/sw/source/core/layout/dbg_lay.cxx b/sw/source/core/layout/dbg_lay.cxx index cd17293ac048..d1d012c6418c 100644 --- a/sw/source/core/layout/dbg_lay.cxx +++ b/sw/source/core/layout/dbg_lay.cxx @@ -106,6 +106,7 @@ #include <frame.hxx> #include <swtable.hxx> #include <ndtxt.hxx> +#include <o3tl/safeint.hxx> #include <o3tl/string_view.hxx> #include <rtl/strbuf.hxx> #include <sal/log.hxx> @@ -482,7 +483,7 @@ static void lcl_Flags(OStringBuffer& rOut, const SwFrame* pFrame) static void lcl_Padded(OStringBuffer& rOut, const OString& s, size_t length) { - if (sal_Int32(length) < s.getLength()) + if (length < o3tl::make_unsigned(s.getLength())) length = s.getLength(); rOut.append(s); for (size_t i = 0; i < length - s.getLength(); i++) diff --git a/xmloff/source/chart/SchXMLTableContext.cxx b/xmloff/source/chart/SchXMLTableContext.cxx index 61eb6c400c13..27ae7311364c 100644 --- a/xmloff/source/chart/SchXMLTableContext.cxx +++ b/xmloff/source/chart/SchXMLTableContext.cxx @@ -959,7 +959,7 @@ void SchXMLTableHelper::switchRangesFromOuterToInternalIfNecessary( } } - if( static_cast<sal_Int32>(aRemainingSeries.size()) != aSeriesSeq.getLength() ) + if( aRemainingSeries.size() != o3tl::make_unsigned(aSeriesSeq.getLength()) ) { //remove the series that have only hidden data xSeriesContainer->setDataSeries( comphelper::containerToSequence(aRemainingSeries) );