toolkit/source/awt/vclxtabpagecontainer.cxx             |    3 ++-
 toolkit/source/awt/vclxtoolkit.cxx                      |    3 ++-
 toolkit/source/awt/vclxtopwindow.cxx                    |    3 ++-
 toolkit/source/controls/controlmodelcontainerbase.cxx   |    3 ++-
 toolkit/source/controls/grid/defaultgridcolumnmodel.cxx |    2 +-
 toolkit/source/controls/roadmapcontrol.cxx              |    6 +++---
 toolkit/source/controls/tabpagecontainer.cxx            |    3 ++-
 toolkit/source/controls/tree/treedatamodel.cxx          |    7 ++++---
 toolkit/source/controls/unocontrols.cxx                 |    6 +++---
 9 files changed, 21 insertions(+), 15 deletions(-)

New commits:
commit ab387593b9a9f5b23df55c12679118dddc8e181a
Author:     Stephan Bergmann <sberg...@redhat.com>
AuthorDate: Tue May 3 14:39:50 2022 +0200
Commit:     Stephan Bergmann <sberg...@redhat.com>
CommitDate: Tue May 3 18:56:13 2022 +0200

    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: I1a9832b5b8b5304fa011a3ed57996a8e3751388b
    Reviewed-on: https://gerrit.libreoffice.org/c/core/+/133760
    Tested-by: Jenkins
    Reviewed-by: Stephan Bergmann <sberg...@redhat.com>

diff --git a/toolkit/source/awt/vclxtabpagecontainer.cxx 
b/toolkit/source/awt/vclxtabpagecontainer.cxx
index e5b74a7f5443..80124c9de868 100644
--- a/toolkit/source/awt/vclxtabpagecontainer.cxx
+++ b/toolkit/source/awt/vclxtabpagecontainer.cxx
@@ -20,6 +20,7 @@
 #include <awt/vclxtabpagecontainer.hxx>
 #include <com/sun/star/awt/tab/XTabPageModel.hpp>
 #include <com/sun/star/awt/XControl.hpp>
+#include <o3tl/safeint.hxx>
 #include <sal/log.hxx>
 #include <toolkit/helper/property.hxx>
 #include <vcl/image.hxx>
@@ -106,7 +107,7 @@ sal_Bool SAL_CALL VCLXTabPageContainer::isTabPageActive( 
::sal_Int16 tabPageInde
 
 Reference< css::awt::tab::XTabPage > SAL_CALL 
VCLXTabPageContainer::getTabPage( ::sal_Int16 tabPageIndex )
 {
-    return (tabPageIndex >= 0 && tabPageIndex < 
static_cast<sal_Int16>(m_aTabPages.size())) ? m_aTabPages[tabPageIndex] : 
nullptr;
+    return (tabPageIndex >= 0 && o3tl::make_unsigned(tabPageIndex) < 
m_aTabPages.size()) ? m_aTabPages[tabPageIndex] : nullptr;
 }
 
 Reference< css::awt::tab::XTabPage > SAL_CALL 
VCLXTabPageContainer::getTabPageByID( ::sal_Int16 tabPageID )
diff --git a/toolkit/source/awt/vclxtoolkit.cxx 
b/toolkit/source/awt/vclxtoolkit.cxx
index fde41f8a30d2..e73511960dea 100644
--- a/toolkit/source/awt/vclxtoolkit.cxx
+++ b/toolkit/source/awt/vclxtoolkit.cxx
@@ -52,6 +52,7 @@
 #include <cppuhelper/bootstrap.hxx>
 #include <cppuhelper/compbase.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
 #include <osl/conditn.hxx>
 #include <osl/module.h>
 #include <osl/thread.hxx>
@@ -1971,7 +1972,7 @@ css::uno::Sequence< css::uno::Reference< 
css::awt::XWindowPeer > > VCLXToolkit::
 
         if ( aDescr.ParentIndex == -1 )
             aDescr.Parent = nullptr;
-        else if ( ( aDescr.ParentIndex >= 0 ) && ( aDescr.ParentIndex < 
static_cast<short>(n) ) )
+        else if ( ( aDescr.ParentIndex >= 0 ) && ( 
o3tl::make_unsigned(aDescr.ParentIndex) < n ) )
             aDescr.Parent = aSeq.getConstArray()[aDescr.ParentIndex];
         aSeq.getArray()[n] = createWindow( aDescr );
     }
diff --git a/toolkit/source/awt/vclxtopwindow.cxx 
b/toolkit/source/awt/vclxtopwindow.cxx
index 7550ddca083e..db42fa80277f 100644
--- a/toolkit/source/awt/vclxtopwindow.cxx
+++ b/toolkit/source/awt/vclxtopwindow.cxx
@@ -31,6 +31,7 @@
 
 #include <vcl/sysdata.hxx>
 #include <comphelper/sequence.hxx>
+#include <o3tl/safeint.hxx>
 
 #include <awt/vclxtopwindow.hxx>
 #include <toolkit/awt/vclxmenu.hxx>
@@ -200,7 +201,7 @@ void SAL_CALL VCLXTopWindow::setDisplay( ::sal_Int32 
_display )
 {
     SolarMutexGuard aGuard;
 
-    if ( ( _display < 0 ) || ( _display >= 
static_cast<sal_Int32>(Application::GetScreenCount()) ) )
+    if ( ( _display < 0 ) || ( o3tl::make_unsigned(_display) >= 
Application::GetScreenCount() ) )
         throw IndexOutOfBoundsException();
 
     SystemWindow* pWindow = VCLXContainer::GetAsDynamic<SystemWindow>();
diff --git a/toolkit/source/controls/controlmodelcontainerbase.cxx 
b/toolkit/source/controls/controlmodelcontainerbase.cxx
index 8cf401c1752b..677d000f9e50 100644
--- a/toolkit/source/controls/controlmodelcontainerbase.cxx
+++ b/toolkit/source/controls/controlmodelcontainerbase.cxx
@@ -20,6 +20,7 @@
 
 #include <controls/controlmodelcontainerbase.hxx>
 #include <vcl/svapp.hxx>
+#include <o3tl/safeint.hxx>
 #include <osl/mutex.hxx>
 #include <toolkit/helper/property.hxx>
 #include <helper/servicenames.hxx>
@@ -820,7 +821,7 @@ void SAL_CALL ControlModelContainerBase::getGroup( 
sal_Int32 _nGroup, Sequence<
 
     implUpdateGroupStructure();
 
-    if ( ( _nGroup < 0 ) || ( _nGroup >= 
static_cast<sal_Int32>(maGroups.size()) ) )
+    if ( ( _nGroup < 0 ) || ( o3tl::make_unsigned(_nGroup) >= maGroups.size() 
) )
     {
         SAL_WARN("toolkit", "invalid argument and I am not allowed to throw 
exception!" );
         _rGroup.realloc( 0 );
diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx 
b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx
index 24eb0cb58bb0..ad17d15ea76d 100644
--- a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx
+++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx
@@ -231,7 +231,7 @@ private:
     {
         ::comphelper::ComponentGuard aGuard( *this, rBHelper );
 
-        if ( index >=0 && index < static_cast<sal_Int32>(m_aColumns.size()))
+        if ( index >=0 && o3tl::make_unsigned(index) < m_aColumns.size())
             return m_aColumns[index];
 
         throw css::lang::IndexOutOfBoundsException();
diff --git a/toolkit/source/controls/roadmapcontrol.cxx 
b/toolkit/source/controls/roadmapcontrol.cxx
index 15c5cd7f1f3f..2640dc6b5b67 100644
--- a/toolkit/source/controls/roadmapcontrol.cxx
+++ b/toolkit/source/controls/roadmapcontrol.cxx
@@ -178,7 +178,7 @@ static void lcl_throwIndexOutOfBoundsException( )
 
     Any SAL_CALL UnoControlRoadmapModel::getByIndex( sal_Int32 Index )
     {
-        if (( Index >= static_cast<sal_Int32>(maRoadmapItems.size())) || 
(Index < 0))
+        if ((Index < 0) || ( o3tl::make_unsigned(Index) >= 
maRoadmapItems.size()))
             lcl_throwIndexOutOfBoundsException( );
         Any aAny( maRoadmapItems.at( Index ) );
         return aAny;
@@ -187,7 +187,7 @@ static void lcl_throwIndexOutOfBoundsException( )
 
     void UnoControlRoadmapModel::MakeRMItemValidation( sal_Int32 Index, const 
Reference< XInterface >& xRoadmapItem )
     {
-        if ((Index > static_cast<sal_Int32>(maRoadmapItems.size())) || ( Index 
< 0 ) )
+        if (( Index < 0 ) || (o3tl::make_unsigned(Index) > 
maRoadmapItems.size()) )
             lcl_throwIndexOutOfBoundsException( );
         if ( !xRoadmapItem.is() )
             lcl_throwIllegalArgumentException();
@@ -288,7 +288,7 @@ static void lcl_throwIndexOutOfBoundsException( )
 
     void SAL_CALL UnoControlRoadmapModel::removeByIndex( sal_Int32 Index)
     {
-        if (( Index > static_cast<sal_Int32>(maRoadmapItems.size())) || (Index 
< 0))
+        if ((Index < 0) || ( o3tl::make_unsigned(Index) > 
maRoadmapItems.size()))
             lcl_throwIndexOutOfBoundsException( );
         Reference< XInterface > xRoadmapItem;
         maRoadmapItems.erase( maRoadmapItems.begin() + Index );
diff --git a/toolkit/source/controls/tabpagecontainer.cxx 
b/toolkit/source/controls/tabpagecontainer.cxx
index b0f437139ea3..d4028b2901f1 100644
--- a/toolkit/source/controls/tabpagecontainer.cxx
+++ b/toolkit/source/controls/tabpagecontainer.cxx
@@ -27,6 +27,7 @@
 #include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
 #include <com/sun/star/uno/XComponentContext.hpp>
 
+#include <o3tl/safeint.hxx>
 #include <tools/diagnose_ex.h>
 #include <vcl/svapp.hxx>
 
@@ -176,7 +177,7 @@ void SAL_CALL 
UnoControlTabPageContainerModel::replaceByIndex( ::sal_Int32 /*Ind
 uno::Any SAL_CALL UnoControlTabPageContainerModel::getByIndex( ::sal_Int32 
nIndex )
 {
     ::osl::Guard< ::osl::Mutex > aGuard( GetMutex() );
-    if ( nIndex < 0 || nIndex > sal_Int32(m_aTabPageVector.size()) )
+    if ( nIndex < 0 || o3tl::make_unsigned(nIndex) > m_aTabPageVector.size() )
         throw lang::IndexOutOfBoundsException();
     return uno::Any(m_aTabPageVector[nIndex]);
 }
diff --git a/toolkit/source/controls/tree/treedatamodel.cxx 
b/toolkit/source/controls/tree/treedatamodel.cxx
index 935fc39d46ff..df8056057a8b 100644
--- a/toolkit/source/controls/tree/treedatamodel.cxx
+++ b/toolkit/source/controls/tree/treedatamodel.cxx
@@ -24,6 +24,7 @@
 #include <com/sun/star/uno/XComponentContext.hpp>
 #include <cppuhelper/implbase2.hxx>
 #include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
 #include <rtl/ref.hxx>
 #include <toolkit/helper/mutexandbroadcasthelper.hxx>
 #include <mutex>
@@ -316,7 +317,7 @@ void SAL_CALL MutableTreeNode::insertChildByIndex( 
sal_Int32 nChildIndex, const
 {
     std::unique_lock aGuard( maMutex );
 
-    if( (nChildIndex < 0) || (nChildIndex > 
static_cast<sal_Int32>(maChildren.size())) )
+    if( (nChildIndex < 0) || (o3tl::make_unsigned(nChildIndex) > 
maChildren.size()) )
         throw IndexOutOfBoundsException();
 
     rtl::Reference< MutableTreeNode > xImpl( dynamic_cast< MutableTreeNode* >( 
xChildNode.get() ) );
@@ -338,7 +339,7 @@ void SAL_CALL MutableTreeNode::removeChildByIndex( 
sal_Int32 nChildIndex )
 {
     std::unique_lock aGuard( maMutex );
 
-    if( (nChildIndex < 0) || (nChildIndex >= 
static_cast<sal_Int32>(maChildren.size())) )
+    if( (nChildIndex < 0) || (o3tl::make_unsigned(nChildIndex) >= 
maChildren.size()) )
         throw IndexOutOfBoundsException();
 
     rtl::Reference< MutableTreeNode > xImpl;
@@ -428,7 +429,7 @@ Reference< XTreeNode > SAL_CALL 
MutableTreeNode::getChildAt( sal_Int32 nChildInd
 {
     std::scoped_lock aGuard( maMutex );
 
-    if( (nChildIndex < 0) || (nChildIndex >= 
static_cast<sal_Int32>(maChildren.size())) )
+    if( (nChildIndex < 0) || (o3tl::make_unsigned(nChildIndex) >= 
maChildren.size()) )
         throw IndexOutOfBoundsException();
     return maChildren[nChildIndex];
 }
diff --git a/toolkit/source/controls/unocontrols.cxx 
b/toolkit/source/controls/unocontrols.cxx
index 2072a761cbdb..e728103d0b28 100644
--- a/toolkit/source/controls/unocontrols.cxx
+++ b/toolkit/source/controls/unocontrols.cxx
@@ -1965,7 +1965,7 @@ struct UnoControlListBoxModel_Data
 
     const ListItem& getItem( const sal_Int32 i_nIndex ) const
     {
-        if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() 
) ) )
+        if ( ( i_nIndex < 0 ) || ( o3tl::make_unsigned(i_nIndex) >= 
m_aListItems.size() ) )
             throw IndexOutOfBoundsException( OUString(), m_rAntiImpl );
         return m_aListItems[ i_nIndex ];
     }
@@ -1977,7 +1977,7 @@ struct UnoControlListBoxModel_Data
 
     ListItem& insertItem( const sal_Int32 i_nIndex )
     {
-        if ( ( i_nIndex < 0 ) || ( i_nIndex > sal_Int32( m_aListItems.size() ) 
) )
+        if ( ( i_nIndex < 0 ) || ( o3tl::make_unsigned(i_nIndex) > 
m_aListItems.size() ) )
             throw IndexOutOfBoundsException( OUString(), m_rAntiImpl );
         return *m_aListItems.insert( m_aListItems.begin() + i_nIndex, 
ListItem() );
     }
@@ -2001,7 +2001,7 @@ struct UnoControlListBoxModel_Data
 
     void    removeItem( const sal_Int32 i_nIndex )
     {
-        if ( ( i_nIndex < 0 ) || ( i_nIndex >= sal_Int32( m_aListItems.size() 
) ) )
+        if ( ( i_nIndex < 0 ) || ( o3tl::make_unsigned(i_nIndex) >= 
m_aListItems.size() ) )
             throw IndexOutOfBoundsException( OUString(), m_rAntiImpl );
         m_aListItems.erase( m_aListItems.begin() + i_nIndex );
     }

Reply via email to