diff options
author | Stephan Bergmann <sbergman@redhat.com> | 2022-05-24 15:26:06 +0200 |
---|---|---|
committer | Stephan Bergmann <sbergman@redhat.com> | 2022-05-24 16:50:03 +0200 |
commit | 5060c5015882b7109c54598c4ea858949beafc43 (patch) | |
tree | c8c153d73f6c6ebbe2dae768c1da72d28312efd4 /forms/source | |
parent | a86818c15a6b4773ddd012db37d55b5204163c24 (diff) |
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: I20600d61a5d59d739bc1bee838c0038e4611aec2
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/134875
Tested-by: Jenkins
Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'forms/source')
-rw-r--r-- | forms/source/component/ListBox.cxx | 2 | ||||
-rw-r--r-- | forms/source/component/entrylisthelper.cxx | 9 | ||||
-rw-r--r-- | forms/source/misc/InterfaceContainer.cxx | 9 | ||||
-rw-r--r-- | forms/source/xforms/binding.cxx | 3 |
4 files changed, 13 insertions, 10 deletions
diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx index d9542504a72b..a6d4bd808086 100644 --- a/forms/source/component/ListBox.cxx +++ b/forms/source/component/ListBox.cxx @@ -1396,7 +1396,7 @@ namespace frm { sal_Int32 nSelectIndex = -1; OSL_VERIFY( _rExternalValue >>= nSelectIndex ); - if ( ( nSelectIndex >= 0 ) && ( nSelectIndex < static_cast<sal_Int32>(getStringItemList().size()) ) ) + if ( ( nSelectIndex >= 0 ) && ( o3tl::make_unsigned(nSelectIndex) < getStringItemList().size() ) ) { aSelectIndexes = { o3tl::narrowing<sal_Int16>(nSelectIndex) }; } diff --git a/forms/source/component/entrylisthelper.cxx b/forms/source/component/entrylisthelper.cxx index 84addb3afb51..0f781076328c 100644 --- a/forms/source/component/entrylisthelper.cxx +++ b/forms/source/component/entrylisthelper.cxx @@ -20,6 +20,7 @@ #include "entrylisthelper.hxx" #include <FormComponent.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <comphelper/sequence.hxx> #include <comphelper/property.hxx> @@ -82,13 +83,13 @@ namespace frm OSL_ENSURE( _rEvent.Source == m_xListSource, "OEntryListHelper::entryChanged: where did this come from?" ); - OSL_ENSURE( ( _rEvent.Position >= 0 ) && ( _rEvent.Position < static_cast<sal_Int32>(m_aStringItems.size()) ), + OSL_ENSURE( ( _rEvent.Position >= 0 ) && ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() ), "OEntryListHelper::entryChanged: invalid index!" ); OSL_ENSURE( _rEvent.Entries.getLength() == 1, "OEntryListHelper::entryChanged: invalid string list!" ); if ( ( _rEvent.Position >= 0 ) - && ( _rEvent.Position < static_cast<sal_Int32>(m_aStringItems.size()) ) + && ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() ) && _rEvent.Entries.hasElements() ) { @@ -106,11 +107,11 @@ namespace frm OSL_ENSURE( _rEvent.Source == m_xListSource, "OEntryListHelper::entryRangeInserted: where did this come from?" ); - OSL_ENSURE( ( _rEvent.Position > 0 ) && ( _rEvent.Position < static_cast<sal_Int32>(m_aStringItems.size()) ) && _rEvent.Entries.hasElements(), + OSL_ENSURE( ( _rEvent.Position > 0 ) && ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() ) && _rEvent.Entries.hasElements(), "OEntryListHelper::entryRangeRemoved: invalid count and/or position!" ); if ( ( _rEvent.Position > 0 ) - && ( _rEvent.Position < static_cast<sal_Int32>(m_aStringItems.size()) ) + && ( o3tl::make_unsigned(_rEvent.Position) < m_aStringItems.size() ) && _rEvent.Entries.hasElements() ) { diff --git a/forms/source/misc/InterfaceContainer.cxx b/forms/source/misc/InterfaceContainer.cxx index f0615970aa44..c797124bfeaf 100644 --- a/forms/source/misc/InterfaceContainer.cxx +++ b/forms/source/misc/InterfaceContainer.cxx @@ -43,6 +43,7 @@ #include <comphelper/sequence.hxx> #include <comphelper/types.hxx> #include <cppuhelper/exc_hlp.hxx> +#include <o3tl/safeint.hxx> #include <tools/debug.hxx> #include <tools/diagnose_ex.h> #include <sal/log.hxx> @@ -722,7 +723,7 @@ sal_Int32 OInterfaceContainer::getCount() Any OInterfaceContainer::getByIndex(sal_Int32 _nIndex) { - if (_nIndex < 0 || (_nIndex >= static_cast<sal_Int32>(m_aItems.size()))) + if (_nIndex < 0 || (o3tl::make_unsigned(_nIndex) >= m_aItems.size())) throw IndexOutOfBoundsException(); return m_aItems[_nIndex]->queryInterface( m_aElementType ); @@ -915,7 +916,7 @@ void SAL_CALL OInterfaceContainer::insertByIndex( sal_Int32 _nIndex, const Any& void OInterfaceContainer::implReplaceByIndex( const sal_Int32 _nIndex, const Any& _rNewElement, ::osl::ClearableMutexGuard& _rClearBeforeNotify ) { - OSL_PRECOND( ( _nIndex >= 0 ) && ( _nIndex < static_cast<sal_Int32>(m_aItems.size()) ), "OInterfaceContainer::implReplaceByIndex: precondition not met (index)!" ); + OSL_PRECOND( ( _nIndex >= 0 ) && ( o3tl::make_unsigned(_nIndex) < m_aItems.size() ), "OInterfaceContainer::implReplaceByIndex: precondition not met (index)!" ); // approve the new object std::unique_ptr< ElementDescription > aElementMetaData( createElementMetaData() ); @@ -991,7 +992,7 @@ void OInterfaceContainer::implReplaceByIndex( const sal_Int32 _nIndex, const Any void OInterfaceContainer::implCheckIndex( const sal_Int32 _nIndex ) { - if (_nIndex < 0 || _nIndex >= static_cast<sal_Int32>(m_aItems.size())) + if (_nIndex < 0 || o3tl::make_unsigned(_nIndex) >= m_aItems.size()) throw IndexOutOfBoundsException(); } @@ -1008,7 +1009,7 @@ void SAL_CALL OInterfaceContainer::replaceByIndex(sal_Int32 _nIndex, const Any& void OInterfaceContainer::implRemoveByIndex( const sal_Int32 _nIndex, ::osl::ClearableMutexGuard& _rClearBeforeNotify ) { - OSL_PRECOND( ( _nIndex >= 0 ) && ( _nIndex < static_cast<sal_Int32>(m_aItems.size()) ), "OInterfaceContainer::implRemoveByIndex: precondition not met (index)!" ); + OSL_PRECOND( ( _nIndex >= 0 ) && ( o3tl::make_unsigned(_nIndex) < m_aItems.size() ), "OInterfaceContainer::implRemoveByIndex: precondition not met (index)!" ); OInterfaceArray::iterator i = m_aItems.begin() + _nIndex; css::uno::Reference<css::uno::XInterface> xElement(*i); diff --git a/forms/source/xforms/binding.cxx b/forms/source/xforms/binding.cxx index e2f6a8ea02c0..32eeefc75de3 100644 --- a/forms/source/xforms/binding.cxx +++ b/forms/source/xforms/binding.cxx @@ -31,6 +31,7 @@ #include <strings.hrc> #include <rtl/ustrbuf.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <tools/diagnose_ex.h> @@ -1042,7 +1043,7 @@ OUString Binding::getListEntry( sal_Int32 nPosition ) // check bounds and return proper item PathExpression::NodeVector_t aNodes = maBindingExpression.getNodeList(); - if( nPosition < 0 || nPosition >= static_cast<sal_Int32>( aNodes.size() ) ) + if( nPosition < 0 || o3tl::make_unsigned(nPosition) >= aNodes.size() ) throw IndexOutOfBoundsException("", static_cast<XValueBinding*>(this)); return lcl_getString( aNodes[ nPosition ] ); } |