summaryrefslogtreecommitdiff
path: root/basic
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2022-05-24 15:26:06 +0200
committerStephan Bergmann <sbergman@redhat.com>2022-05-24 16:50:03 +0200
commit5060c5015882b7109c54598c4ea858949beafc43 (patch)
treec8c153d73f6c6ebbe2dae768c1da72d28312efd4 /basic
parenta86818c15a6b4773ddd012db37d55b5204163c24 (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 'basic')
-rw-r--r--basic/source/classes/sb.cxx5
-rw-r--r--basic/source/sbx/sbxarray.cxx2
-rw-r--r--basic/source/sbx/sbxcoll.cxx5
3 files changed, 7 insertions, 5 deletions
diff --git a/basic/source/classes/sb.cxx b/basic/source/classes/sb.cxx
index 570447246cf9..4e3e716a56ca 100644
--- a/basic/source/classes/sb.cxx
+++ b/basic/source/classes/sb.cxx
@@ -18,6 +18,7 @@
*/
#include <sb.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/stream.hxx>
#include <tools/debug.hxx>
@@ -2172,7 +2173,7 @@ void BasicCollection::CollItem( SbxArray* pPar_ )
SbxVariable* pRes = nullptr;
SbxVariable* p = pPar_->Get(1);
sal_Int32 nIndex = implGetIndex( p );
- if (nIndex >= 0 && nIndex < static_cast<sal_Int32>(xItemArray->Count()))
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < xItemArray->Count())
{
pRes = xItemArray->Get(nIndex);
}
@@ -2196,7 +2197,7 @@ void BasicCollection::CollRemove( SbxArray* pPar_ )
SbxVariable* p = pPar_->Get(1);
sal_Int32 nIndex = implGetIndex( p );
- if (nIndex >= 0 && nIndex < static_cast<sal_Int32>(xItemArray->Count()))
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < xItemArray->Count())
{
xItemArray->Remove( nIndex );
diff --git a/basic/source/sbx/sbxarray.cxx b/basic/source/sbx/sbxarray.cxx
index 53c0ed36fa73..4bd933b126ad 100644
--- a/basic/source/sbx/sbxarray.cxx
+++ b/basic/source/sbx/sbxarray.cxx
@@ -448,7 +448,7 @@ void SbxDimArray::unoAddDim( sal_Int32 lb, sal_Int32 ub )
bool SbxDimArray::GetDim( sal_Int32 n, sal_Int32& rlb, sal_Int32& rub ) const
{
- if( n < 1 || n > static_cast<sal_Int32>(m_vDimensions.size()) )
+ if( n < 1 || o3tl::make_unsigned(n) > m_vDimensions.size() )
{
SetError( ERRCODE_BASIC_OUT_OF_RANGE );
rub = rlb = 0;
diff --git a/basic/source/sbx/sbxcoll.cxx b/basic/source/sbx/sbxcoll.cxx
index ea4eb4cdea14..328115d4f6fa 100644
--- a/basic/source/sbx/sbxcoll.cxx
+++ b/basic/source/sbx/sbxcoll.cxx
@@ -17,6 +17,7 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <o3tl/safeint.hxx>
#include <tools/stream.hxx>
#include <basic/sbx.hxx>
@@ -188,7 +189,7 @@ void SbxCollection::CollItem( SbxArray* pPar_ )
else
{
short n = p->GetInteger();
- if (n >= 1 && n <= static_cast<sal_Int32>(pObjs->Count()))
+ if (n >= 1 && o3tl::make_unsigned(n) <= pObjs->Count())
{
pRes = pObjs->Get(static_cast<sal_uInt32>(n) - 1);
}
@@ -210,7 +211,7 @@ void SbxCollection::CollRemove( SbxArray* pPar_ )
else
{
short n = pPar_->Get(1)->GetInteger();
- if (n < 1 || n > static_cast<sal_Int32>(pObjs->Count()))
+ if (n < 1 || o3tl::make_unsigned(n) > pObjs->Count())
SetError( ERRCODE_BASIC_BAD_INDEX );
else
Remove(pObjs->Get(static_cast<sal_uInt32>(n) - 1));