From bdff0bb77b57def835fcaed3bded7519e69dc896 Mon Sep 17 00:00:00 2001 From: Stephan Bergmann Date: Tue, 26 Apr 2022 15:08:36 +0200 Subject: Use o3tl::make_unsigned in some places ...where a signed and an unsigned value are compared, and the signed value has just been proven to be non-negative here Change-Id: I9665e6c2c4c5557f2d4cf1bb646f9fffc7bd7d30 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133442 Tested-by: Jenkins Reviewed-by: Stephan Bergmann --- comphelper/source/container/IndexedPropertyValuesContainer.cxx | 3 ++- comphelper/source/container/interfacecontainer2.cxx | 3 ++- comphelper/source/misc/accessiblekeybindinghelper.cxx | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) (limited to 'comphelper') diff --git a/comphelper/source/container/IndexedPropertyValuesContainer.cxx b/comphelper/source/container/IndexedPropertyValuesContainer.cxx index c0086061b033..08b46518bebf 100644 --- a/comphelper/source/container/IndexedPropertyValuesContainer.cxx +++ b/comphelper/source/container/IndexedPropertyValuesContainer.cxx @@ -25,6 +25,7 @@ #include #include #include +#include #include @@ -89,7 +90,7 @@ void SAL_CALL IndexedPropertyValuesContainer::insertByIndex( sal_Int32 nIndex, c void SAL_CALL IndexedPropertyValuesContainer::removeByIndex( sal_Int32 nIndex ) { - if ((nIndex >= sal_Int32(maProperties.size())) || (nIndex < 0)) + if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maProperties.size())) throw lang::IndexOutOfBoundsException(); maProperties.erase(maProperties.begin() + nIndex); diff --git a/comphelper/source/container/interfacecontainer2.cxx b/comphelper/source/container/interfacecontainer2.cxx index 0881ccbe44cf..9acff0a7f761 100644 --- a/comphelper/source/container/interfacecontainer2.cxx +++ b/comphelper/source/container/interfacecontainer2.cxx @@ -21,6 +21,7 @@ #include #include +#include #include #include @@ -103,7 +104,7 @@ void OInterfaceIteratorHelper2::remove() if( bIsList ) { OSL_ASSERT( nRemain >= 0 && - nRemain < static_cast(aData.pAsVector->size()) ); + o3tl::make_unsigned(nRemain) < aData.pAsVector->size() ); rCont.removeInterface( (*aData.pAsVector)[nRemain] ); } else diff --git a/comphelper/source/misc/accessiblekeybindinghelper.cxx b/comphelper/source/misc/accessiblekeybindinghelper.cxx index cf16f157c5e3..d1db69b98fa8 100644 --- a/comphelper/source/misc/accessiblekeybindinghelper.cxx +++ b/comphelper/source/misc/accessiblekeybindinghelper.cxx @@ -21,6 +21,7 @@ #include #include +#include namespace comphelper @@ -83,7 +84,7 @@ namespace comphelper { std::scoped_lock aGuard( m_aMutex ); - if ( nIndex < 0 || nIndex >= static_cast(m_aKeyBindings.size()) ) + if ( nIndex < 0 || o3tl::make_unsigned(nIndex) >= m_aKeyBindings.size() ) throw IndexOutOfBoundsException(); return m_aKeyBindings[nIndex]; -- cgit