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 /sc | |
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 'sc')
-rw-r--r-- | sc/source/core/data/dptabsrc.cxx | 2 | ||||
-rw-r--r-- | sc/source/core/data/markmulti.cxx | 4 | ||||
-rw-r--r-- | sc/source/core/tool/queryparam.cxx | 3 | ||||
-rw-r--r-- | sc/source/filter/oox/pivottablebuffer.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/docshell/impex.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/appluno.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/unoobj/chart2uno.cxx | 2 | ||||
-rw-r--r-- | sc/source/ui/unoobj/dapiuno.cxx | 5 | ||||
-rw-r--r-- | sc/source/ui/unoobj/fmtuno.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/unoobj/nameuno.cxx | 3 | ||||
-rw-r--r-- | sc/source/ui/vba/vbafiledialogitems.cxx | 5 |
11 files changed, 23 insertions, 12 deletions
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx index 17a6cc17171c..cab605f69080 100644 --- a/sc/source/core/data/dptabsrc.cxx +++ b/sc/source/core/data/dptabsrc.cxx @@ -2604,7 +2604,7 @@ const ScDPItemData* ScDPSource::GetItemDataById(sal_Int32 nDim, sal_Int32 nId) const ScDPItemData* ScDPMembers::GetSrcItemDataByIndex(SCROW nIndex) { const std::vector< SCROW >& memberIds = pSource->GetData()->GetColumnEntries( nDim ); - if ( nIndex >= static_cast<tools::Long>(memberIds.size()) || nIndex < 0 ) + if ( nIndex < 0 || o3tl::make_unsigned(nIndex) >= memberIds.size() ) return nullptr; SCROW nId = memberIds[ nIndex ]; return pSource->GetItemDataById( nDim, nId ); diff --git a/sc/source/core/data/markmulti.cxx b/sc/source/core/data/markmulti.cxx index 3d8aef3cfafc..4c92f5f25a47 100644 --- a/sc/source/core/data/markmulti.cxx +++ b/sc/source/core/data/markmulti.cxx @@ -23,6 +23,8 @@ #include <segmenttree.hxx> #include <sheetlimits.hxx> +#include <o3tl/safeint.hxx> + #include <algorithm> ScMultiSel::ScMultiSel(const ScSheetLimits& rSheetLimits) @@ -384,7 +386,7 @@ void ScMultiSel::ShiftCols(SCCOL nStartCol, sal_Int32 nColOffset) } aRowSel = aNewMultiSel.aRowSel; - if (!(nColOffset > 0 && nStartCol > 0 && nStartCol < static_cast<SCCOL>(aNewMultiSel.aMultiSelContainer.size()))) + if (!(nColOffset > 0 && nStartCol > 0 && o3tl::make_unsigned(nStartCol) < aNewMultiSel.aMultiSelContainer.size())) return; // insert nColOffset new columns, and select their cells if they are selected diff --git a/sc/source/core/tool/queryparam.cxx b/sc/source/core/tool/queryparam.cxx index 80aa2185c0b3..286a1ef4ff64 100644 --- a/sc/source/core/tool/queryparam.cxx +++ b/sc/source/core/tool/queryparam.cxx @@ -24,6 +24,7 @@ #include <svl/sharedstringpool.hxx> #include <svl/numformat.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <algorithm> @@ -453,7 +454,7 @@ bool ScDBQueryParamMatrix::IsValidFieldIndex() const { SCSIZE nC, nR; mpMatrix->GetDimensions(nC, nR); - return 0 <= mnField && mnField <= static_cast<SCCOL>(nC); + return 0 <= mnField && o3tl::make_unsigned(mnField) <= nC; } ScDBQueryParamMatrix::~ScDBQueryParamMatrix() diff --git a/sc/source/filter/oox/pivottablebuffer.cxx b/sc/source/filter/oox/pivottablebuffer.cxx index 142ec1b2406e..6d73e26928a9 100644 --- a/sc/source/filter/oox/pivottablebuffer.cxx +++ b/sc/source/filter/oox/pivottablebuffer.cxx @@ -40,6 +40,7 @@ #include <com/sun/star/xml/sax/XFastAttributeList.hpp> #include <comphelper/sequence.hxx> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <tools/diagnose_ex.h> #include <sal/log.hxx> @@ -551,7 +552,7 @@ void PivotTableField::convertPageField( const PTPageFieldModel& rPageField ) else { // single item may be selected - if( (0 <= rPageField.mnItem) && (rPageField.mnItem < static_cast< sal_Int32 >( maItems.size() )) ) + if( (0 <= rPageField.mnItem) && (o3tl::make_unsigned(rPageField.mnItem) < maItems.size()) ) nCacheItem = maItems[ rPageField.mnItem ].mnCacheItem; } diff --git a/sc/source/ui/docshell/impex.cxx b/sc/source/ui/docshell/impex.cxx index 76ddae4f2ef1..6e6c57f44683 100644 --- a/sc/source/ui/docshell/impex.cxx +++ b/sc/source/ui/docshell/impex.cxx @@ -2294,7 +2294,7 @@ bool ScImportExport::Sylk2Doc( SvStream& rStrm ) if( nCol > nEndCol ) nEndCol = nCol; } - if ( 0 <= nFormat && nFormat < static_cast<sal_Int32>(aFormats.size()) && !bInvalidCol && !bInvalidRow ) + if ( 0 <= nFormat && o3tl::make_unsigned(nFormat) < aFormats.size() && !bInvalidCol && !bInvalidRow ) { sal_uInt32 nKey = aFormats[nFormat]; rDoc.ApplyAttr( nCol, nRow, aRange.aStart.Tab(), diff --git a/sc/source/ui/unoobj/appluno.cxx b/sc/source/ui/unoobj/appluno.cxx index 4096c5f4c384..998d7ef50a7d 100644 --- a/sc/source/ui/unoobj/appluno.cxx +++ b/sc/source/ui/unoobj/appluno.cxx @@ -19,6 +19,7 @@ #include <appluno.hxx> #include <sal/types.h> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <formula/funcvarargs.h> @@ -544,7 +545,7 @@ uno::Any SAL_CALL ScFunctionListObj::getByIndex( sal_Int32 nIndex ) if ( !pFuncList ) throw uno::RuntimeException(); // should not happen - if ( nIndex >= 0 && nIndex < static_cast<sal_Int32>(pFuncList->GetCount()) ) + if ( nIndex >= 0 && o3tl::make_unsigned(nIndex) < pFuncList->GetCount() ) { const ScFuncDesc* pDesc = pFuncList->GetFunction(nIndex); if ( pDesc ) diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx index 194b166e6bf5..d2fec774e125 100644 --- a/sc/source/ui/unoobj/chart2uno.cxx +++ b/sc/source/ui/unoobj/chart2uno.cxx @@ -3205,7 +3205,7 @@ sal_uInt32 getDisplayNumberFormat(const ScDocument* pDoc, const ScAddress& rPos) return 0; } - if (nIndex < 0 || nIndex >= static_cast<sal_Int32>(m_aDataArray.size())) + if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= m_aDataArray.size()) { SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'."); return 0; diff --git a/sc/source/ui/unoobj/dapiuno.cxx b/sc/source/ui/unoobj/dapiuno.cxx index 4bf5018e2cd4..64111c1c3437 100644 --- a/sc/source/ui/unoobj/dapiuno.cxx +++ b/sc/source/ui/unoobj/dapiuno.cxx @@ -20,6 +20,7 @@ #include <algorithm> #include <cmath> +#include <o3tl/safeint.hxx> #include <svl/hint.hxx> #include <vcl/svapp.hxx> #include <sal/log.hxx> @@ -2832,7 +2833,7 @@ sal_Int32 SAL_CALL ScDataPilotFieldGroupsObj::getCount() Any SAL_CALL ScDataPilotFieldGroupsObj::getByIndex( sal_Int32 nIndex ) { SolarMutexGuard aGuard; - if ((nIndex < 0) || (nIndex >= static_cast< sal_Int32 >( maGroups.size() ))) + if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maGroups.size())) throw IndexOutOfBoundsException(); return Any( Reference< XNameAccess >( new ScDataPilotFieldGroupObj( *this, maGroups[ nIndex ].maName ) ) ); } @@ -3004,7 +3005,7 @@ Any SAL_CALL ScDataPilotFieldGroupObj::getByIndex( sal_Int32 nIndex ) { SolarMutexGuard aGuard; ScFieldGroupMembers& rMembers = mxParent->getFieldGroup( maGroupName ).maMembers; - if ((nIndex < 0) || (nIndex >= static_cast< sal_Int32 >( rMembers.size() ))) + if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= rMembers.size())) throw IndexOutOfBoundsException(); return Any( Reference< XNamed >( new ScDataPilotFieldGroupItemObj( *this, rMembers[ nIndex ] ) ) ); } diff --git a/sc/source/ui/unoobj/fmtuno.cxx b/sc/source/ui/unoobj/fmtuno.cxx index 2446ad8e5b50..64ff2841922c 100644 --- a/sc/source/ui/unoobj/fmtuno.cxx +++ b/sc/source/ui/unoobj/fmtuno.cxx @@ -19,6 +19,7 @@ #include <sal/config.h> +#include <o3tl/safeint.hxx> #include <osl/diagnose.h> #include <svl/style.hxx> #include <vcl/svapp.hxx> @@ -342,7 +343,7 @@ void SAL_CALL ScTableConditionalFormat::removeByIndex( sal_Int32 nIndex ) { SolarMutexGuard aGuard; - if (nIndex < static_cast<sal_Int32>(maEntries.size()) && nIndex >= 0) + if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < maEntries.size()) { maEntries.erase(maEntries.begin()+nIndex); } diff --git a/sc/source/ui/unoobj/nameuno.cxx b/sc/source/ui/unoobj/nameuno.cxx index ea54ee508831..1a1184c002be 100644 --- a/sc/source/ui/unoobj/nameuno.cxx +++ b/sc/source/ui/unoobj/nameuno.cxx @@ -17,6 +17,7 @@ * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ +#include <o3tl/safeint.hxx> #include <svl/hint.hxx> #include <vcl/svapp.hxx> #include <com/sun/star/lang/IndexOutOfBoundsException.hpp> @@ -1087,7 +1088,7 @@ void SAL_CALL ScLabelRangesObj::removeByIndex( sal_Int32 nIndex ) ScDocument& rDoc = pDocShell->GetDocument(); ScRangePairList* pOldList = bColumn ? rDoc.GetColNameRanges() : rDoc.GetRowNameRanges(); - if ( pOldList && nIndex >= 0 && nIndex < static_cast<sal_Int32>(pOldList->size()) ) + if ( pOldList && nIndex >= 0 && o3tl::make_unsigned(nIndex) < pOldList->size() ) { ScRangePairListRef xNewList(pOldList->Clone()); diff --git a/sc/source/ui/vba/vbafiledialogitems.cxx b/sc/source/ui/vba/vbafiledialogitems.cxx index f64f706d3a7c..d34ace3c55e3 100644 --- a/sc/source/ui/vba/vbafiledialogitems.cxx +++ b/sc/source/ui/vba/vbafiledialogitems.cxx @@ -16,6 +16,9 @@ * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 . */ + +#include <o3tl/safeint.hxx> + #include "vbafiledialogitems.hxx" using namespace ::com::sun::star; @@ -71,7 +74,7 @@ ScVbaFileDialogSelectedItems::createCollectionObject( const uno::Any& aSource ) sal_Int32 nPosition = -1; if (!(aSource >>= nPosition)) throw uno::RuntimeException("not an sal_Int32"); - if (nPosition < 0 || nPosition >= static_cast<sal_Int32>(m_sItems.size())) + if (nPosition < 0 || o3tl::make_unsigned(nPosition) >= m_sItems.size()) throw uno::RuntimeException("out of range"); OUString sPath = m_sItems[nPosition]; |