summaryrefslogtreecommitdiff
path: root/connectivity
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 /connectivity
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 'connectivity')
-rw-r--r--connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx3
-rw-r--r--connectivity/source/commontools/paramwrapper.cxx3
-rw-r--r--connectivity/source/drivers/file/FPreparedStatement.cxx3
-rw-r--r--connectivity/source/drivers/file/FResultSet.cxx3
-rw-r--r--connectivity/source/drivers/file/FResultSetMetaData.cxx3
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx3
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx2
-rw-r--r--connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_preparedstatement.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_xcolumns.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_xcontainer.cxx7
-rw-r--r--connectivity/source/drivers/postgresql/pq_xindexes.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_xkeys.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_xtables.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_xusers.cxx3
-rw-r--r--connectivity/source/drivers/postgresql/pq_xviews.cxx3
-rw-r--r--connectivity/source/inc/file/FResultSet.hxx3
-rw-r--r--connectivity/source/parse/sqliterator.cxx5
18 files changed, 38 insertions, 21 deletions
diff --git a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
index d88d9b932f4c..3c755f206224 100644
--- a/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
+++ b/connectivity/source/commontools/FDatabaseMetaDataResultSet.cxx
@@ -27,6 +27,7 @@
#include <comphelper/sequence.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <connectivity/dbexception.hxx>
+#include <o3tl/safeint.hxx>
#include <o3tl/unreachable.hxx>
#include <TConnection.hxx>
@@ -171,7 +172,7 @@ sal_Int32 SAL_CALL ODatabaseMetaDataResultSet::findColumn( const OUString& colum
void ODatabaseMetaDataResultSet::checkIndex(sal_Int32 columnIndex )
{
- if(columnIndex >= static_cast<sal_Int32>((*m_aRowsIter).size()) || columnIndex < 1)
+ if(columnIndex < 1 || o3tl::make_unsigned(columnIndex) >= (*m_aRowsIter).size())
::dbtools::throwInvalidIndexException(*this);
}
diff --git a/connectivity/source/commontools/paramwrapper.cxx b/connectivity/source/commontools/paramwrapper.cxx
index aab6daa243d1..820e2ae9ed62 100644
--- a/connectivity/source/commontools/paramwrapper.cxx
+++ b/connectivity/source/commontools/paramwrapper.cxx
@@ -28,6 +28,7 @@
#include <com/sun/star/sdb/XSingleSelectQueryAnalyzer.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
#include <comphelper/enumhelper.hxx>
@@ -310,7 +311,7 @@ namespace dbtools::param
::osl::MutexGuard aGuard( m_aMutex );
impl_checkDisposed_throw();
- if ( ( _nIndex < 0 ) || ( _nIndex >= static_cast<sal_Int32>(m_aParameters.size()) ) )
+ if ( ( _nIndex < 0 ) || ( o3tl::make_unsigned(_nIndex) >= m_aParameters.size() ) )
throw IndexOutOfBoundsException();
return Any( Reference< XPropertySet >( m_aParameters[ _nIndex ] ) );
diff --git a/connectivity/source/drivers/file/FPreparedStatement.cxx b/connectivity/source/drivers/file/FPreparedStatement.cxx
index 2ae516800b06..f2a8571b61e5 100644
--- a/connectivity/source/drivers/file/FPreparedStatement.cxx
+++ b/connectivity/source/drivers/file/FPreparedStatement.cxx
@@ -18,6 +18,7 @@
*/
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <file/FPreparedStatement.hxx>
#include <com/sun/star/sdbc/DataType.hpp>
@@ -392,7 +393,7 @@ void SAL_CALL OPreparedStatement::release() noexcept
void OPreparedStatement::checkAndResizeParameters(sal_Int32 parameterIndex)
{
::connectivity::checkDisposed(OStatement_BASE::rBHelper.bDisposed);
- if ( m_aAssignValues.is() && (parameterIndex < 1 || parameterIndex >= static_cast<sal_Int32>(m_aParameterIndexes.size())) )
+ if ( m_aAssignValues.is() && (parameterIndex < 1 || o3tl::make_unsigned(parameterIndex) >= m_aParameterIndexes.size()) )
throwInvalidIndexException(*this);
else if ( static_cast<sal_Int32>(m_aParameterRow->size()) <= parameterIndex )
{
diff --git a/connectivity/source/drivers/file/FResultSet.cxx b/connectivity/source/drivers/file/FResultSet.cxx
index 43ad38739d5b..4d0e256b931e 100644
--- a/connectivity/source/drivers/file/FResultSet.cxx
+++ b/connectivity/source/drivers/file/FResultSet.cxx
@@ -29,6 +29,7 @@
#include <cppuhelper/typeprovider.hxx>
#include <connectivity/dbtools.hxx>
#include <cppuhelper/propshlp.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <iterator>
#include <com/sun/star/sdbc/ResultSetType.hpp>
@@ -921,7 +922,7 @@ bool OResultSet::Move(IResultSetHelper::Movement eCursorPosition, sal_Int32 nOff
// The FileCursor is outside of the valid range, if:
// a.) m_nRowPos < 1
// b.) a KeySet exists and m_nRowPos > m_pFileSet->size()
- if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && m_nRowPos >= static_cast<sal_Int32>(m_pFileSet->size()) )) // && m_pFileSet->IsFrozen()
+ if (m_nRowPos < 0 || (m_pFileSet->isFrozen() && eCursorPosition != IResultSetHelper::BOOKMARK && o3tl::make_unsigned(m_nRowPos) >= m_pFileSet->size() )) // && m_pFileSet->IsFrozen()
{
goto Error;
}
diff --git a/connectivity/source/drivers/file/FResultSetMetaData.cxx b/connectivity/source/drivers/file/FResultSetMetaData.cxx
index f68a06532bb7..fdc944043d2a 100644
--- a/connectivity/source/drivers/file/FResultSetMetaData.cxx
+++ b/connectivity/source/drivers/file/FResultSetMetaData.cxx
@@ -22,6 +22,7 @@
#include <comphelper/extract.hxx>
#include <connectivity/dbexception.hxx>
#include <comphelper/types.hxx>
+#include <o3tl/safeint.hxx>
using namespace ::comphelper;
@@ -51,7 +52,7 @@ OResultSetMetaData::~OResultSetMetaData()
void OResultSetMetaData::checkColumnIndex(sal_Int32 column)
{
- if(column <= 0 || column > static_cast<sal_Int32>(m_xColumns->size()))
+ if(column <= 0 || o3tl::make_unsigned(column) > m_xColumns->size())
throwInvalidIndexException(*this);
}
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx
index a50b14bbb3b4..6ec6a89f175c 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_preparedstatement.cxx
@@ -23,6 +23,7 @@
#include "mysqlc_propertyids.hxx"
#include "mysqlc_resultsetmetadata.hxx"
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <com/sun/star/sdbc/DataType.hpp>
@@ -569,7 +570,7 @@ void OPreparedStatement::setFastPropertyValue_NoBroadcast(sal_Int32 nHandle, con
void OPreparedStatement::checkParameterIndex(sal_Int32 column)
{
- if (column < 1 || column > static_cast<sal_Int32>(m_paramCount))
+ if (column < 1 || o3tl::make_unsigned(column) > m_paramCount)
{
throw SQLException("Parameter index out of range", *this, OUString(), 1, Any());
}
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
index 7410ad38e6fc..f1c23ca482ad 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultset.cxx
@@ -1095,7 +1095,7 @@ css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL OResultSet::getProper
void OResultSet::checkColumnIndex(sal_Int32 index)
{
- if (index < 1 || index > static_cast<int>(m_aFields.size()))
+ if (index < 1 || o3tl::make_unsigned(index) > m_aFields.size())
{
/* static object for efficiency or thread safety is a problem ? */
throw SQLException("index out of range", *this, OUString(), 1, Any());
diff --git a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx
index 6fc531fa943d..84cd6be2a3a7 100644
--- a/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx
+++ b/connectivity/source/drivers/mysqlc/mysqlc_resultsetmetadata.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
+#include <o3tl/safeint.hxx>
using namespace connectivity::mysqlc;
using namespace com::sun::star::uno;
@@ -199,7 +200,7 @@ sal_Bool SAL_CALL OResultSetMetaData::isWritable(sal_Int32 column)
void OResultSetMetaData::checkColumnIndex(sal_Int32 columnIndex)
{
auto nColCount = m_fields.size();
- if (columnIndex < 1 || columnIndex > static_cast<sal_Int32>(nColCount))
+ if (columnIndex < 1 || o3tl::make_unsigned(columnIndex) > nColCount)
{
OUString str = "Column index out of range (expected 1 to "
+ OUString::number(sal_Int32(nColCount)) + ", got "
diff --git a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
index d7a73289b077..2f31b4226c08 100644
--- a/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
+++ b/connectivity/source/drivers/postgresql/pq_preparedstatement.cxx
@@ -40,6 +40,7 @@
#include "pq_statics.hxx"
#include "pq_statement.hxx"
+#include <o3tl/safeint.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
@@ -197,7 +198,7 @@ PreparedStatement::~PreparedStatement()
void PreparedStatement::checkColumnIndex( sal_Int32 parameterIndex )
{
- if( parameterIndex < 1 || parameterIndex > static_cast<sal_Int32>(m_vars.size()) )
+ if( parameterIndex < 1 || o3tl::make_unsigned(parameterIndex) > m_vars.size() )
{
throw SQLException(
"pq_preparedstatement: parameter index out of range (expected 1 to "
diff --git a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx
index 6caf1decc6c6..f1d3c0a53e88 100644
--- a/connectivity/source/drivers/postgresql/pq_xcolumns.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xcolumns.cxx
@@ -38,6 +38,7 @@
#include <string_view>
+#include <o3tl/safeint.hxx>
#include <o3tl/string_view.hxx>
#include <rtl/ref.hxx>
#include <rtl/ustrbuf.hxx>
@@ -492,7 +493,7 @@ void Columns::appendByDescriptor(
void Columns::dropByIndex( sal_Int32 index )
{
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"COLUMNS: Index out of range (allowed 0 to "
diff --git a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx
index 993045d3a44d..fea88b682cdb 100644
--- a/connectivity/source/drivers/postgresql/pq_xcontainer.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xcontainer.cxx
@@ -37,6 +37,7 @@
#include <com/sun/star/container/ElementExistException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <cppuhelper/implbase.hxx>
+#include <o3tl/safeint.hxx>
#include "pq_xcontainer.hxx"
#include "pq_statics.hxx"
@@ -155,7 +156,7 @@ Any Container::getByName( const OUString& aName )
"Element " + aName + " unknown in " + m_type + "-Container",
*this );
}
- OSL_ASSERT( ii->second >= 0 && ii->second < static_cast<int>(m_values.size()) );
+ OSL_ASSERT( ii->second >= 0 && o3tl::make_unsigned(ii->second) < m_values.size() );
return m_values[ ii->second ];
}
@@ -188,7 +189,7 @@ sal_Bool Container::hasElements( )
Any Container::getByIndex( sal_Int32 Index )
{
- if( Index < 0 || Index >= static_cast<sal_Int32>(m_values.size()) )
+ if( Index < 0 || o3tl::make_unsigned(Index) >= m_values.size() )
{
throw IndexOutOfBoundsException(
"Index " + OUString::number( Index )
@@ -298,7 +299,7 @@ void Container::dropByName( const OUString& elementName )
void Container::dropByIndex( sal_Int32 index )
{
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >=static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >=m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"Index out of range (allowed 0 to "
diff --git a/connectivity/source/drivers/postgresql/pq_xindexes.cxx b/connectivity/source/drivers/postgresql/pq_xindexes.cxx
index d027e15b9d3c..ef1e7116a1b0 100644
--- a/connectivity/source/drivers/postgresql/pq_xindexes.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xindexes.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/sdbc/XRow.hpp>
#include <com/sun/star/sdbc/XParameters.hpp>
#include <cppuhelper/exc_hlp.hxx>
+#include <o3tl/safeint.hxx>
#include "pq_xindexes.hxx"
#include "pq_xindex.hxx"
@@ -234,7 +235,7 @@ void Indexes::dropByIndex( sal_Int32 index )
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"Indexes: Index out of range (allowed 0 to "
diff --git a/connectivity/source/drivers/postgresql/pq_xkeys.cxx b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
index 0aeb32446abb..dced2bc9baa5 100644
--- a/connectivity/source/drivers/postgresql/pq_xkeys.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xkeys.cxx
@@ -49,6 +49,7 @@
#include <com/sun/star/sdbc/KeyRule.hpp>
#include <com/sun/star/sdbcx/KeyType.hpp>
#include <cppuhelper/exc_hlp.hxx>
+#include <o3tl/safeint.hxx>
#include "pq_xkeys.hxx"
#include "pq_xkey.hxx"
@@ -226,7 +227,7 @@ void Keys::appendByDescriptor(
void Keys::dropByIndex( sal_Int32 index )
{
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1)
diff --git a/connectivity/source/drivers/postgresql/pq_xtables.cxx b/connectivity/source/drivers/postgresql/pq_xtables.cxx
index f1a089ff031a..423ec81f2166 100644
--- a/connectivity/source/drivers/postgresql/pq_xtables.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xtables.cxx
@@ -43,6 +43,7 @@
#include <com/sun/star/sdbcx/Privilege.hpp>
#include <com/sun/star/sdbc/DataType.hpp>
#include <cppuhelper/exc_hlp.hxx>
+#include <o3tl/safeint.hxx>
#include "pq_xtables.hxx"
#include "pq_xviews.hxx"
@@ -310,7 +311,7 @@ void Tables::appendByDescriptor(
void Tables::dropByIndex( sal_Int32 index )
{
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"TABLES: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1)
diff --git a/connectivity/source/drivers/postgresql/pq_xusers.cxx b/connectivity/source/drivers/postgresql/pq_xusers.cxx
index a12c86ed2375..08cdf2d1c135 100644
--- a/connectivity/source/drivers/postgresql/pq_xusers.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xusers.cxx
@@ -41,6 +41,7 @@
#include <com/sun/star/sdbc/SQLException.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <cppuhelper/exc_hlp.hxx>
+#include <o3tl/safeint.hxx>
#include "pq_xusers.hxx"
#include "pq_xuser.hxx"
@@ -151,7 +152,7 @@ void Users::dropByIndex( sal_Int32 index )
{
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"USERS: Index out of range (allowed 0 to "
diff --git a/connectivity/source/drivers/postgresql/pq_xviews.cxx b/connectivity/source/drivers/postgresql/pq_xviews.cxx
index 3dfdfaa5fe64..1f5b6c4fa52c 100644
--- a/connectivity/source/drivers/postgresql/pq_xviews.cxx
+++ b/connectivity/source/drivers/postgresql/pq_xviews.cxx
@@ -41,6 +41,7 @@
#include <com/sun/star/sdbc/SQLException.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
#include <cppuhelper/exc_hlp.hxx>
+#include <o3tl/safeint.hxx>
#include "pq_xviews.hxx"
#include "pq_xview.hxx"
@@ -175,7 +176,7 @@ void Views::dropByName( const OUString& elementName )
void Views::dropByIndex( sal_Int32 index )
{
osl::MutexGuard guard( m_xMutex->GetMutex() );
- if( index < 0 || index >= static_cast<sal_Int32>(m_values.size()) )
+ if( index < 0 || o3tl::make_unsigned(index) >= m_values.size() )
{
throw css::lang::IndexOutOfBoundsException(
"VIEWS: Index out of range (allowed 0 to " + OUString::number(m_values.size() -1)
diff --git a/connectivity/source/inc/file/FResultSet.hxx b/connectivity/source/inc/file/FResultSet.hxx
index a7aa77ff2576..62a52fe2bc82 100644
--- a/connectivity/source/inc/file/FResultSet.hxx
+++ b/connectivity/source/inc/file/FResultSet.hxx
@@ -40,6 +40,7 @@
#include <TSortIndex.hxx>
#include <TSkipDeletedSet.hxx>
#include <com/sun/star/lang/XEventListener.hpp>
+#include <o3tl/safeint.hxx>
namespace connectivity::file
{
@@ -292,7 +293,7 @@ namespace connectivity::file
OSL_ENSURE(column > 0, "file::OResultSet::mapColumn: invalid column index!");
// the first column (index 0) is for convenience only. The first real select column is number 1.
- if ((column > 0) && (column < static_cast<sal_Int32>(m_aColMapping.size())))
+ if ((column > 0) && (o3tl::make_unsigned(column) < m_aColMapping.size()))
map = m_aColMapping[column];
return map;
diff --git a/connectivity/source/parse/sqliterator.cxx b/connectivity/source/parse/sqliterator.cxx
index 83d6342fa84b..fcebd2879a4f 100644
--- a/connectivity/source/parse/sqliterator.cxx
+++ b/connectivity/source/parse/sqliterator.cxx
@@ -37,6 +37,7 @@
#include <comphelper/types.hxx>
#include <connectivity/dbmetadata.hxx>
#include <com/sun/star/sdb/SQLFilterOperator.hpp>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <iterator>
@@ -1758,7 +1759,7 @@ void OSQLParseTreeIterator::setOrderByColumnName(const OUString & rColumnName, O
else
{
sal_Int32 nId = rColumnName.toInt32();
- if ( nId > 0 && nId < static_cast<sal_Int32>(m_aSelectColumns->size()) )
+ if ( nId > 0 && o3tl::make_unsigned(nId) < m_aSelectColumns->size() )
m_aOrderColumns->push_back( new OOrderColumn( (*m_aSelectColumns)[nId-1], isCaseSensitive(), bAscending ) );
}
@@ -1779,7 +1780,7 @@ void OSQLParseTreeIterator::setGroupByColumnName(const OUString & rColumnName, O
else
{
sal_Int32 nId = rColumnName.toInt32();
- if ( nId > 0 && nId < static_cast<sal_Int32>(m_aSelectColumns->size()) )
+ if ( nId > 0 && o3tl::make_unsigned(nId) < m_aSelectColumns->size() )
m_aGroupColumns->push_back(new OParseColumn((*m_aSelectColumns)[nId-1],isCaseSensitive()));
}