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 /dbaccess | |
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 'dbaccess')
-rw-r--r-- | dbaccess/source/core/api/RowSet.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/core/api/RowSetCache.cxx | 8 | ||||
-rw-r--r-- | dbaccess/source/core/api/StaticSet.cxx | 5 | ||||
-rw-r--r-- | dbaccess/source/core/dataaccess/bookmarkcontainer.cxx | 3 | ||||
-rw-r--r-- | dbaccess/source/core/dataaccess/definitioncontainer.cxx | 3 | ||||
-rw-r--r-- | dbaccess/source/ui/control/ColumnControlWindow.cxx | 3 | ||||
-rw-r--r-- | dbaccess/source/ui/dlg/indexfieldscontrol.cxx | 3 | ||||
-rw-r--r-- | dbaccess/source/ui/tabledesign/TEditControl.cxx | 3 | ||||
-rw-r--r-- | dbaccess/source/ui/uno/copytablewizard.cxx | 3 |
9 files changed, 20 insertions, 13 deletions
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx index 0f0a21bfb98f..28c3929953c2 100644 --- a/dbaccess/source/core/api/RowSet.cxx +++ b/dbaccess/source/core/api/RowSet.cxx @@ -2701,7 +2701,7 @@ void ORowSet::checkUpdateConditions(sal_Int32 columnIndex) if ( m_aCurrentRow.isNull() ) ::dbtools::throwSQLException( DBA_RES( RID_STR_INVALID_CURSOR_STATE ), StandardSQLState::INVALID_CURSOR_STATE, *this ); - if ( columnIndex <= 0 || sal_Int32((*m_aCurrentRow)->size()) <= columnIndex ) + if ( columnIndex <= 0 || (*m_aCurrentRow)->size() <= o3tl::make_unsigned(columnIndex) ) ::dbtools::throwSQLException( DBA_RES( RID_STR_INVALID_INDEX ), StandardSQLState::INVALID_DESCRIPTOR_INDEX, *this ); } diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx index e3059f889b6b..46b2cea95a02 100644 --- a/dbaccess/source/core/api/RowSetCache.cxx +++ b/dbaccess/source/core/api/RowSetCache.cxx @@ -946,7 +946,7 @@ void ORowSetCache::moveWindow() if ( nRowsInCache < m_nFetchSize ) { // There is some unused space in *m_pMatrix; fill it - OSL_ENSURE((nRowsInCache >= static_cast<ORowSetMatrix::difference_type>(0)) && (nRowsInCache < static_cast<sal_Int32>(m_pMatrix->size())),"Position is invalid!"); + OSL_ENSURE((nRowsInCache >= static_cast<ORowSetMatrix::difference_type>(0)) && (o3tl::make_unsigned(nRowsInCache) < m_pMatrix->size()),"Position is invalid!"); sal_Int32 nPos = m_nEndPos + 1; bool bCheck = m_xCacheSet->absolute(nPos); ORowSetMatrix::iterator aIter = m_pMatrix->begin() + nRowsInCache; @@ -964,7 +964,7 @@ void ORowSetCache::moveWindow() // The rows behind this can be reused ORowSetMatrix::iterator aIter = m_pMatrix->begin(); const sal_Int32 nNewStartPosInMatrix = nNewStartPos - m_nStartPos; - OSL_ENSURE((nNewStartPosInMatrix >= static_cast<ORowSetMatrix::difference_type>(0)) && (nNewStartPosInMatrix < static_cast<sal_Int32>(m_pMatrix->size())),"Position is invalid!"); + OSL_ENSURE((nNewStartPosInMatrix >= static_cast<ORowSetMatrix::difference_type>(0)) && (o3tl::make_unsigned(nNewStartPosInMatrix) < m_pMatrix->size()),"Position is invalid!"); // first position we reuse const ORowSetMatrix::const_iterator aEnd = m_pMatrix->begin() + nNewStartPosInMatrix; // End of used portion of the matrix. Is < m_pMatrix->end() if less data than window size @@ -1623,8 +1623,8 @@ void ORowSetCache::clearInsertRow() ORowSetMatrix::iterator ORowSetCache::calcPosition() const { sal_Int32 nValue = (m_nPosition - m_nStartPos) - 1; - OSL_ENSURE((nValue >= static_cast<ORowSetMatrix::difference_type>(0)) && (nValue < static_cast<sal_Int32>(m_pMatrix->size())),"Position is invalid!"); - return ( nValue < 0 || nValue >= static_cast<sal_Int32>(m_pMatrix->size()) ) ? m_pMatrix->end() : (m_pMatrix->begin() + nValue); + OSL_ENSURE((nValue >= static_cast<ORowSetMatrix::difference_type>(0)) && (o3tl::make_unsigned(nValue) < m_pMatrix->size()),"Position is invalid!"); + return ( nValue < 0 || o3tl::make_unsigned(nValue) >= m_pMatrix->size() ) ? m_pMatrix->end() : (m_pMatrix->begin() + nValue); } TORowSetOldRowHelperRef ORowSetCache::registerOldRow() diff --git a/dbaccess/source/core/api/StaticSet.cxx b/dbaccess/source/core/api/StaticSet.cxx index a7ea00c4376b..97226b466dbd 100644 --- a/dbaccess/source/core/api/StaticSet.cxx +++ b/dbaccess/source/core/api/StaticSet.cxx @@ -23,6 +23,7 @@ #include <com/sun/star/beans/XPropertySet.hpp> #include <connectivity/CommonTools.hxx> #include <comphelper/types.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> using namespace dbaccess; @@ -193,7 +194,7 @@ bool OStaticSet::absolute( sal_Int32 row ) } else if(row > 0) { - if(row >= static_cast<sal_Int32>(m_aSet.size())) + if(o3tl::make_unsigned(row) >= m_aSet.size()) { if(!m_bEnd) { @@ -202,7 +203,7 @@ bool OStaticSet::absolute( sal_Int32 row ) bNext = fetchRow(); } - if(row > static_cast<sal_Int32>(m_aSet.size())) + if(o3tl::make_unsigned(row) > m_aSet.size()) m_aSetIter = m_aSet.end(); // check again else m_aSetIter = m_aSet.begin() + row; diff --git a/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx b/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx index 4072002ba326..a03caea57e93 100644 --- a/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx +++ b/dbaccess/source/core/dataaccess/bookmarkcontainer.cxx @@ -19,6 +19,7 @@ #include <bookmarkcontainer.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <comphelper/enumhelper.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> @@ -206,7 +207,7 @@ Any SAL_CALL OBookmarkContainer::getByIndex( sal_Int32 _nIndex ) { MutexGuard aGuard(m_rMutex); - if ((_nIndex < 0) || (_nIndex >= static_cast<sal_Int32>(m_aBookmarksIndexed.size()))) + if ((_nIndex < 0) || (o3tl::make_unsigned(_nIndex) >= m_aBookmarksIndexed.size())) throw IndexOutOfBoundsException(); return Any(m_aBookmarksIndexed[_nIndex]->second); diff --git a/dbaccess/source/core/dataaccess/definitioncontainer.cxx b/dbaccess/source/core/dataaccess/definitioncontainer.cxx index d3023f2885ab..81d8b03026bb 100644 --- a/dbaccess/source/core/dataaccess/definitioncontainer.cxx +++ b/dbaccess/source/core/dataaccess/definitioncontainer.cxx @@ -23,6 +23,7 @@ #include <strings.hxx> #include <tools/diagnose_ex.h> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <comphelper/enumhelper.hxx> #include <cppuhelper/exc_hlp.hxx> @@ -372,7 +373,7 @@ Any SAL_CALL ODefinitionContainer::getByIndex( sal_Int32 _nIndex ) { MutexGuard aGuard(m_aMutex); - if ((_nIndex < 0) || (_nIndex >= static_cast<sal_Int32>(m_aDocuments.size()))) + if ((_nIndex < 0) || (o3tl::make_unsigned(_nIndex) >= m_aDocuments.size())) throw IndexOutOfBoundsException(); Documents::iterator aPos = m_aDocuments[_nIndex]; diff --git a/dbaccess/source/ui/control/ColumnControlWindow.cxx b/dbaccess/source/ui/control/ColumnControlWindow.cxx index 7a419a6cfb8c..f9f786f22ec3 100644 --- a/dbaccess/source/ui/control/ColumnControlWindow.cxx +++ b/dbaccess/source/ui/control/ColumnControlWindow.cxx @@ -21,6 +21,7 @@ #include <unotools/syslocale.hxx> #include <i18nlangtag/languagetag.hxx> #include <connectivity/dbtools.hxx> +#include <o3tl/safeint.hxx> #include <UITools.hxx> #include <core_resource.hxx> #include <strings.hrc> @@ -121,7 +122,7 @@ Reference< XNumberFormatter > OColumnControlWindow::GetFormatter() const TOTypeInfoSP OColumnControlWindow::getTypeInfo(sal_Int32 _nPos) { - return ( _nPos >= 0 && _nPos < static_cast<sal_Int32>(m_aDestTypeInfoIndex.size())) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP(); + return ( _nPos >= 0 && o3tl::make_unsigned(_nPos) < m_aDestTypeInfoIndex.size()) ? m_aDestTypeInfoIndex[_nPos]->second : TOTypeInfoSP(); } const OTypeInfoMap* OColumnControlWindow::getTypeInfo() const diff --git a/dbaccess/source/ui/dlg/indexfieldscontrol.cxx b/dbaccess/source/ui/dlg/indexfieldscontrol.cxx index 3770fb737e1a..35b0e3f02a27 100644 --- a/dbaccess/source/ui/dlg/indexfieldscontrol.cxx +++ b/dbaccess/source/ui/dlg/indexfieldscontrol.cxx @@ -20,6 +20,7 @@ #include <core_resource.hxx> #include <indexfieldscontrol.hxx> #include <strings.hrc> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <helpids.h> #include <toolkit/helper/vclunohelper.hxx> @@ -266,7 +267,7 @@ constexpr auto BROWSER_STANDARD_FLAGS = BrowserMode::COLUMNSELECTION | BrowserMo bool IndexFieldsControl::implGetFieldDesc(sal_Int32 _nRow, IndexFields::const_iterator& _rPos) { _rPos = m_aFields.end(); - if ((_nRow < 0) || (_nRow >= static_cast<sal_Int32>(m_aFields.size()))) + if ((_nRow < 0) || (o3tl::make_unsigned(_nRow) >= m_aFields.size())) return false; _rPos = m_aFields.begin() + _nRow; return true; diff --git a/dbaccess/source/ui/tabledesign/TEditControl.cxx b/dbaccess/source/ui/tabledesign/TEditControl.cxx index cd2149efbf54..5f7809882cc6 100644 --- a/dbaccess/source/ui/tabledesign/TEditControl.cxx +++ b/dbaccess/source/ui/tabledesign/TEditControl.cxx @@ -36,6 +36,7 @@ #include <connectivity/dbtools.hxx> #include <SqlNameEdit.hxx> #include <TableRowExchange.hxx> +#include <o3tl/safeint.hxx> #include <sot/storage.hxx> #include <svx/svxids.hrc> #include <UITools.hxx> @@ -1602,7 +1603,7 @@ void OTableEditorCtrl::SwitchType( const TOTypeInfoSP& _pType ) // Store the old description pDescrWin->SaveData( pActFieldDescr ); - if ( nRow < 0 || nRow > static_cast<tools::Long>(m_pRowList->size()) ) + if ( nRow < 0 || o3tl::make_unsigned(nRow) > m_pRowList->size() ) return; // Show the new description std::shared_ptr<OTableRow> pRow = (*m_pRowList)[nRow]; diff --git a/dbaccess/source/ui/uno/copytablewizard.cxx b/dbaccess/source/ui/uno/copytablewizard.cxx index 14b4609476db..2645952f4b5e 100644 --- a/dbaccess/source/ui/uno/copytablewizard.cxx +++ b/dbaccess/source/ui/uno/copytablewizard.cxx @@ -60,6 +60,7 @@ #include <cppuhelper/exc_hlp.hxx> #include <cppuhelper/implbase.hxx> #include <comphelper/interfacecontainer3.hxx> +#include <o3tl/safeint.hxx> #include <rtl/ustrbuf.hxx> #include <sal/log.hxx> #include <svtools/genericunodialog.hxx> @@ -1150,7 +1151,7 @@ void CopyTableWizard::impl_copyRows_throw( const Reference< XResultSet >& _rxSou continue; } - if ( ( nSourceColumn < 1 ) || ( nSourceColumn >= static_cast<sal_Int32>(aSourceColTypes.size()) ) ) + if ( ( nSourceColumn < 1 ) || ( o3tl::make_unsigned(nSourceColumn) >= aSourceColTypes.size() ) ) { // ( we have to check here against 1 because the parameters are 1 based) ::dbtools::throwSQLException("Internal error: invalid column type index.", ::dbtools::StandardSQLState::INVALID_DESCRIPTOR_INDEX, *this); |