summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2020-01-27 09:30:39 +0100
committerStephan Bergmann <sbergman@redhat.com>2020-01-28 07:42:15 +0100
commitaef7feb3e695ecf6d411f0777196dcc4281e201a (patch)
tree6adff7e08e6431ff87c575d026e330badb9a6cd3
parent65f007c629e5a7b2710e21e3f26164b433576e27 (diff)
New loplugin:unsignedcompare
"Find explicit casts from signed to unsigned integer in comparison against unsigned integer, where the cast is presumably used to avoid warnings about signed vs. unsigned comparisons, and could thus be replaced with o3tl::make_unsigned for clairty." (compilerplugins/clang/unsignedcompare.cxx) o3tl::make_unsigned requires its argument to be non-negative, and there is a chance that some original code like static_cast<sal_uInt32>(n) >= c used the explicit cast to actually force a (potentially negative) value of sal_Int32 to be interpreted as an unsigned sal_uInt32, rather than using the cast to avoid a false "signed vs. unsigned comparison" warning in a case where n is known to be non-negative. It appears that restricting this plugin to non- equality comparisons (<, >, <=, >=) and excluding equality comparisons (==, !=) is a useful heuristic to avoid such false positives. The only remainging false positive I found was 0288c8ffecff4956a52b9147d441979941e8b87f "Rephrase cast from sal_Int32 to sal_uInt32". But which of course does not mean that there were no further false positivies that I missed. So this commit may accidentally introduce some false hits of the assert in o3tl::make_unsigned. At least, it passed a full (Linux ASan+UBSan --enable-dbgutil) `make check && make screenshot`. It is by design that o3tl::make_unsigned only accepts signed integer parameter types (and is not defined as a nop for unsigned ones), to avoid unnecessary uses which would in general be suspicious. But the STATIC_ARRAY_SELECT macro in include/oox/helper/helper.hxx is used with both signed and unsigned types, so needs a little oox::detail::make_unsigned helper function for now. (The ultimate fix being to get rid of the macro in the first place.) Change-Id: Ia4adc9f44c70ad1dfd608784cac39ee922c32175 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/87556 Tested-by: Jenkins Reviewed-by: Stephan Bergmann <sbergman@redhat.com>
-rw-r--r--accessibility/source/standard/vclxaccessiblelist.cxx2
-rw-r--r--accessibility/source/standard/vclxaccessibletabcontrol.cxx9
-rw-r--r--accessibility/source/standard/vclxaccessibletoolbox.cxx7
-rw-r--r--avmedia/source/gstreamer/gstframegrabber.cxx4
-rw-r--r--avmedia/source/gstreamer/gstplayer.cxx4
-rw-r--r--basic/source/runtime/runtime.cxx4
-rw-r--r--basic/source/sbx/sbxarray.cxx4
-rw-r--r--basic/source/sbx/sbxbyte.cxx5
-rw-r--r--basic/source/sbx/sbxint.cxx3
-rw-r--r--binaryurp/source/bridgefactory.cxx3
-rw-r--r--chart2/source/controller/accessibility/AccessibleBase.cxx3
-rw-r--r--chart2/source/controller/dialogs/DataBrowser.cxx5
-rw-r--r--chart2/source/controller/dialogs/DataBrowserModel.cxx11
-rw-r--r--chart2/source/controller/drawinglayer/ViewElementListProvider.cxx4
-rw-r--r--chart2/source/controller/main/ElementSelector.cxx3
-rw-r--r--chart2/source/model/main/BaseCoordinateSystem.cxx3
-rw-r--r--chart2/source/tools/ExplicitCategoriesProvider.cxx3
-rw-r--r--chart2/source/view/axes/Tickmarks_Equidistant.hxx4
-rw-r--r--comphelper/source/eventattachermgr/eventattachermgr.cxx9
-rw-r--r--comphelper/source/streaming/oslfile2streamwrap.cxx3
-rw-r--r--compilerplugins/clang/test/unsignedcompare.cxx16
-rw-r--r--compilerplugins/clang/unsignedcompare.cxx231
-rw-r--r--configmgr/source/dconf.cxx22
-rw-r--r--configmgr/source/writemodfile.cxx3
-rw-r--r--connectivity/source/commontools/dbtools.cxx3
-rw-r--r--connectivity/source/commontools/parameters.cxx5
-rw-r--r--connectivity/source/drivers/dbase/DTable.cxx17
-rw-r--r--connectivity/source/drivers/dbase/dindexnode.cxx3
-rw-r--r--connectivity/source/drivers/file/FStatement.cxx5
-rw-r--r--connectivity/source/drivers/flat/ETable.cxx9
-rw-r--r--connectivity/source/drivers/mork/MResultSet.cxx3
-rw-r--r--connectivity/source/drivers/odbc/OResultSet.cxx3
-rw-r--r--connectivity/source/drivers/odbc/OTools.cxx5
-rw-r--r--cppuhelper/source/servicemanager.cxx7
-rw-r--r--cui/source/options/optgenrl.cxx5
-rw-r--r--cui/source/tabpages/numfmt.cxx5
-rw-r--r--dbaccess/source/core/api/RowSet.cxx9
-rw-r--r--dbaccess/source/core/api/RowSetBase.cxx3
-rw-r--r--dbaccess/source/core/api/RowSetCache.cxx3
-rw-r--r--dbaccess/source/ui/browser/formadapter.cxx9
-rw-r--r--dbaccess/source/ui/control/RelationControl.cxx5
-rw-r--r--dbaccess/source/ui/dlg/generalpage.cxx5
-rw-r--r--dbaccess/source/ui/dlg/paramdialog.cxx7
-rw-r--r--dbaccess/source/ui/misc/WCopyTable.cxx4
-rw-r--r--dbaccess/source/ui/querydesign/JAccess.cxx3
-rw-r--r--dbaccess/source/ui/querydesign/QueryDesignView.cxx3
-rw-r--r--drawinglayer/source/tools/emfpbrush.cxx15
-rw-r--r--drawinglayer/source/tools/emfppath.cxx3
-rw-r--r--drawinglayer/source/tools/emfppen.cxx5
-rw-r--r--editeng/source/accessibility/AccessibleParaManager.cxx35
-rw-r--r--editeng/source/editeng/editobj.cxx12
-rw-r--r--editeng/source/editeng/edtspell.cxx3
-rw-r--r--editeng/source/editeng/impedit2.cxx5
-rw-r--r--editeng/source/editeng/impedit3.cxx3
-rw-r--r--editeng/source/editeng/impedit4.cxx3
-rw-r--r--editeng/source/items/textitem.cxx3
-rw-r--r--editeng/source/outliner/outliner.cxx3
-rw-r--r--editeng/source/outliner/outlobj.cxx5
-rw-r--r--editeng/source/outliner/paralist.cxx10
-rw-r--r--editeng/source/outliner/paralist.hxx3
-rw-r--r--editeng/source/uno/unotext2.cxx3
-rw-r--r--emfio/source/reader/mtftools.cxx6
-rw-r--r--emfio/source/reader/wmfreader.cxx3
-rw-r--r--extensions/source/dbpilots/groupboxwiz.cxx5
-rw-r--r--extensions/source/scanner/sane.cxx4
-rw-r--r--extensions/source/scanner/scanunx.cxx9
-rw-r--r--filter/source/graphicfilter/icgm/cgm.cxx8
-rw-r--r--filter/source/graphicfilter/icgm/class1.cxx2
-rw-r--r--filter/source/graphicfilter/icgm/class7.cxx5
-rw-r--r--filter/source/graphicfilter/idxf/dxfentrd.cxx9
-rw-r--r--filter/source/graphicfilter/ieps/ieps.cxx6
-rw-r--r--filter/source/msfilter/msdffimp.cxx7
-rw-r--r--filter/source/msfilter/mstoolbar.cxx3
-rw-r--r--filter/source/msfilter/svdfppt.cxx4
-rw-r--r--forms/source/component/Filter.cxx3
-rw-r--r--forms/source/component/GroupManager.cxx3
-rw-r--r--forms/source/component/ListBox.cxx5
-rw-r--r--fpicker/source/office/fileview.cxx3
-rw-r--r--framework/source/fwe/classes/addonsoptions.cxx7
-rw-r--r--framework/source/services/autorecovery.cxx3
-rw-r--r--framework/source/uielement/addonstoolbarmanager.cxx3
-rw-r--r--framework/source/uifactory/addonstoolbarfactory.cxx5
-rw-r--r--hwpfilter/source/hwpfile.cxx21
-rw-r--r--hwpfilter/source/hwpreader.cxx3
-rw-r--r--i18npool/source/breakiterator/breakiterator_th.cxx7
-rw-r--r--idlc/source/idlccompile.cxx3
-rw-r--r--include/oox/helper/helper.hxx17
-rw-r--r--linguistic/source/gciterator.cxx5
-rw-r--r--oox/source/core/contexthandler2.cxx3
-rw-r--r--oox/source/export/drawingml.cxx3
-rw-r--r--opencl/source/opencl_device.cxx3
-rw-r--r--reportdesign/source/filter/xml/xmlTable.cxx7
-rw-r--r--reportdesign/source/ui/dlg/CondFormat.cxx4
-rw-r--r--reportdesign/source/ui/inspection/GeometryHandler.cxx3
-rw-r--r--reportdesign/source/ui/misc/FunctionHelper.cxx7
-rw-r--r--sal/osl/unx/file.cxx3
-rw-r--r--sal/osl/unx/file_url.cxx3
-rw-r--r--sal/osl/unx/pipe.cxx3
-rw-r--r--sal/osl/unx/security.cxx11
-rw-r--r--sal/textenc/converter.cxx3
-rw-r--r--sc/source/core/data/column.cxx11
-rw-r--r--sc/source/core/data/column2.cxx10
-rw-r--r--sc/source/core/data/column4.cxx9
-rw-r--r--sc/source/core/data/columnspanset.cxx6
-rw-r--r--sc/source/core/data/dociter.cxx3
-rw-r--r--sc/source/core/data/documen2.cxx3
-rw-r--r--sc/source/core/data/document.cxx11
-rw-r--r--sc/source/core/data/documentimport.cxx5
-rw-r--r--sc/source/core/data/dpcache.cxx5
-rw-r--r--sc/source/core/data/dpfilteredcache.cxx4
-rw-r--r--sc/source/core/data/dpoutput.cxx19
-rw-r--r--sc/source/core/data/dptabres.cxx11
-rw-r--r--sc/source/core/data/dptabsrc.cxx5
-rw-r--r--sc/source/core/data/table1.cxx3
-rw-r--r--sc/source/core/data/table2.cxx5
-rw-r--r--sc/source/core/tool/compiler.cxx7
-rw-r--r--sc/source/core/tool/dbdata.cxx3
-rw-r--r--sc/source/core/tool/grouparealistener.cxx3
-rw-r--r--sc/source/core/tool/interpr1.cxx13
-rw-r--r--sc/source/core/tool/interpr4.cxx5
-rw-r--r--sc/source/core/tool/token.cxx3
-rw-r--r--sc/source/filter/excel/excdoc.cxx5
-rw-r--r--sc/source/filter/excel/excform8.cxx4
-rw-r--r--sc/source/filter/excel/impop.cxx3
-rw-r--r--sc/source/filter/excel/xeformula.cxx7
-rw-r--r--sc/source/filter/excel/xepivotxml.cxx3
-rw-r--r--sc/source/filter/excel/xestring.cxx5
-rw-r--r--sc/source/filter/excel/xestyle.cxx3
-rw-r--r--sc/source/filter/excel/xiview.cxx6
-rw-r--r--sc/source/filter/excel/xladdress.cxx5
-rw-r--r--sc/source/filter/oox/externallinkbuffer.cxx3
-rw-r--r--sc/source/filter/oox/formulabuffer.cxx13
-rw-r--r--sc/source/filter/oox/pivotcachebuffer.cxx3
-rw-r--r--sc/source/filter/xml/XMLStylesExportHelper.cxx45
-rw-r--r--sc/source/ui/Accessibility/AccessibleDocument.cxx6
-rw-r--r--sc/source/ui/Accessibility/AccessibleFilterMenu.cxx11
-rw-r--r--sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx5
-rw-r--r--sc/source/ui/condformat/condformathelper.cxx5
-rw-r--r--sc/source/ui/dbgui/consdlg.cxx3
-rw-r--r--sc/source/ui/docshell/docfunc.cxx3
-rw-r--r--sc/source/ui/docshell/externalrefmgr.cxx11
-rw-r--r--sc/source/ui/unoobj/PivotTableDataProvider.cxx7
-rw-r--r--sc/source/ui/unoobj/PivotTableDataSequence.cxx4
-rw-r--r--sc/source/ui/unoobj/cellsuno.cxx5
-rw-r--r--sc/source/ui/unoobj/chart2uno.cxx5
-rw-r--r--sc/source/ui/unoobj/condformatuno.cxx7
-rw-r--r--sc/source/ui/unoobj/docuno.cxx5
-rw-r--r--sc/source/ui/vba/vbawindow.cxx3
-rw-r--r--sc/source/ui/vba/vbawindows.cxx3
-rw-r--r--sc/source/ui/view/viewdata.cxx8
-rw-r--r--sd/qa/unit/export-tests.cxx2
-rw-r--r--sd/qa/unit/sdmodeltestbase.hxx4
-rw-r--r--sd/source/core/CustomAnimationEffect.cxx3
-rw-r--r--sd/source/core/sdpage.cxx3
-rw-r--r--sd/source/filter/html/htmlex.cxx3
-rw-r--r--sd/source/filter/pdf/sdpdffilter.cxx5
-rw-r--r--sd/source/ui/accessibility/AccessibleSlideSorterView.cxx5
-rw-r--r--sd/source/ui/animations/SlideTransitionPane.cxx3
-rw-r--r--sd/source/ui/dlg/tpaction.cxx6
-rw-r--r--sd/source/ui/sidebar/MasterPageContainer.cxx7
-rw-r--r--sd/source/ui/sidebar/MasterPagesSelector.cxx3
-rw-r--r--sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx6
-rw-r--r--sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx3
-rw-r--r--sd/source/ui/slidesorter/view/SlsLayeredDevice.cxx11
-rw-r--r--sdext/source/pdfimport/pdfparse/pdfparse.cxx5
-rw-r--r--sdext/source/presenter/PresenterAccessibility.cxx3
-rw-r--r--sdext/source/presenter/PresenterTextView.cxx5
-rw-r--r--sfx2/source/appl/sfxhelp.cxx5
-rw-r--r--sfx2/source/bastyp/mieclip.cxx5
-rw-r--r--sfx2/source/dialog/dockwin.cxx3
-rw-r--r--sfx2/source/sidebar/TabBar.cxx5
-rw-r--r--slideshow/source/engine/opengl/TransitionImpl.hxx3
-rw-r--r--slideshow/source/engine/shapes/drawshapesubsetting.cxx8
-rw-r--r--solenv/CompilerTest_compilerplugins_clang.mk1
-rw-r--r--sot/source/sdstor/stgelem.cxx4
-rw-r--r--starmath/source/AccessibleSmElementsControl.cxx5
-rw-r--r--stoc/source/typeconv/convert.cxx13
-rw-r--r--svl/source/items/macitem.cxx3
-rw-r--r--svl/source/misc/strmadpt.cxx4
-rw-r--r--svl/source/numbers/zforscan.cxx3
-rw-r--r--svtools/source/brwbox/brwbox1.cxx3
-rw-r--r--svtools/source/brwbox/brwbox2.cxx2
-rw-r--r--svtools/source/control/valueset.cxx13
-rw-r--r--svtools/source/dialogs/ServerDetailsControls.cxx3
-rw-r--r--svtools/source/uno/unocontroltablemodel.cxx6
-rw-r--r--svx/source/accessibility/ChildrenManagerImpl.cxx4
-rw-r--r--svx/source/accessibility/GraphCtlAccessibleContext.cxx3
-rw-r--r--svx/source/dialog/frmsel.cxx5
-rw-r--r--svx/source/form/filtnav.cxx7
-rw-r--r--svx/source/form/fmshimp.cxx4
-rw-r--r--svx/source/form/fmsrcimp.cxx8
-rw-r--r--svx/source/form/formcontroller.cxx7
-rw-r--r--svx/source/form/navigatortreemodel.cxx3
-rw-r--r--svx/source/items/numfmtsh.cxx12
-rw-r--r--svx/source/svdraw/svdotextpathdecomposition.cxx4
-rw-r--r--svx/source/svdraw/svdpage.cxx3
-rw-r--r--svx/source/tbxctrls/tbcontrl.cxx3
-rw-r--r--svx/source/unodraw/unopage.cxx3
-rw-r--r--svx/source/unodraw/unoshap2.cxx3
-rw-r--r--svx/source/unodraw/unoshap3.cxx3
-rw-r--r--svx/source/xoutdev/xtable.cxx3
-rw-r--r--sw/qa/extras/globalfilter/globalfilter.cxx5
-rw-r--r--sw/source/core/access/accselectionhelper.cxx5
-rw-r--r--sw/source/core/access/acctable.cxx5
-rw-r--r--sw/source/core/crsr/findtxt.cxx3
-rw-r--r--sw/source/core/doc/DocumentContentOperationsManager.cxx3
-rw-r--r--sw/source/core/doc/doccomp.cxx7
-rw-r--r--sw/source/core/doc/docnum.cxx5
-rw-r--r--sw/source/core/edit/edglss.cxx5
-rw-r--r--sw/source/core/fields/cellfml.cxx5
-rw-r--r--sw/source/core/text/itradj.cxx6
-rw-r--r--sw/source/core/text/redlnitr.cxx3
-rw-r--r--sw/source/core/tox/ToxWhitespaceStripper.cxx3
-rw-r--r--sw/source/core/txtnode/txtedt.cxx3
-rw-r--r--sw/source/core/unocore/unocoll.cxx5
-rw-r--r--sw/source/core/unocore/unofield.cxx3
-rw-r--r--sw/source/core/unocore/unoflatpara.cxx5
-rw-r--r--sw/source/core/unocore/unoobj.cxx3
-rw-r--r--sw/source/core/unocore/unoobj2.cxx3
-rw-r--r--sw/source/core/unocore/unoredlines.cxx3
-rw-r--r--sw/source/core/unocore/unostyle.cxx5
-rw-r--r--sw/source/core/unocore/unotbl.cxx7
-rw-r--r--sw/source/core/unocore/unotextmarkup.cxx5
-rw-r--r--sw/source/filter/basflt/fltshell.cxx3
-rw-r--r--sw/source/filter/html/htmlplug.cxx3
-rw-r--r--sw/source/filter/ww8/wrtww8.cxx5
-rw-r--r--sw/source/filter/ww8/ww8atr.cxx5
-rw-r--r--sw/source/filter/ww8/ww8par.cxx9
-rw-r--r--sw/source/filter/ww8/ww8par2.cxx11
-rw-r--r--sw/source/filter/ww8/ww8par6.cxx5
-rw-r--r--sw/source/filter/ww8/ww8scan.cxx8
-rw-r--r--sw/source/filter/ww8/ww8toolbar.cxx9
-rw-r--r--sw/source/ui/dbui/mmaddressblockpage.cxx3
-rw-r--r--sw/source/ui/fldui/fldref.cxx3
-rw-r--r--sw/source/ui/frmdlg/frmpage.cxx3
-rw-r--r--sw/source/ui/index/cnttab.cxx5
-rw-r--r--sw/source/uibase/dbui/mailmergehelper.cxx5
-rw-r--r--sw/source/uibase/uno/unoatxt.cxx7
-rw-r--r--test/source/sheet/xdatapilotdescriptor.cxx3
-rw-r--r--toolkit/source/awt/animatedimagespeer.cxx3
-rw-r--r--toolkit/source/controls/animatedimages.cxx4
-rw-r--r--toolkit/source/controls/grid/defaultgridcolumnmodel.cxx3
-rw-r--r--toolkit/source/controls/grid/defaultgriddatamodel.cxx19
-rw-r--r--toolkit/source/controls/grid/sortablegriddatamodel.cxx7
-rw-r--r--toolkit/source/controls/unocontrols.cxx14
-rw-r--r--tools/source/stream/stream.cxx11
-rw-r--r--unotools/source/accessibility/accessiblerelationsethelper.cxx3
-rw-r--r--unotools/source/streaming/streamhelper.cxx3
-rw-r--r--unotools/source/streaming/streamwrap.cxx3
-rw-r--r--unotools/source/ucbhelper/xtempfile.cxx3
-rw-r--r--unoxml/source/dom/elementlist.cxx3
-rw-r--r--vbahelper/source/vbahelper/vbadocumentsbase.cxx3
-rw-r--r--vcl/inc/listbox.hxx5
-rw-r--r--vcl/qt5/Qt5Menu.cxx9
-rw-r--r--vcl/source/app/salvtables.cxx17
-rw-r--r--vcl/source/control/edit.cxx10
-rw-r--r--vcl/source/control/imivctl.hxx7
-rw-r--r--vcl/source/control/imivctl2.cxx2
-rw-r--r--vcl/source/control/imp_listbox.cxx5
-rw-r--r--vcl/source/filter/FilterConfigCache.cxx5
-rw-r--r--vcl/source/fontsubset/cff.cxx3
-rw-r--r--vcl/source/gdi/dibtools.cxx7
-rw-r--r--vcl/source/gdi/pdfextoutdevdata.cxx7
-rw-r--r--vcl/source/gdi/pdfwriter_impl.hxx3
-rw-r--r--vcl/source/gdi/svmconverter.cxx6
-rw-r--r--vcl/source/treelist/svimpbox.cxx7
-rw-r--r--vcl/source/treelist/svtabbx.cxx3
-rw-r--r--vcl/source/window/syswin.cxx10
-rw-r--r--vcl/source/window/winproc.cxx5
-rw-r--r--vcl/unx/generic/app/i18n_cb.cxx3
-rw-r--r--vcl/unx/generic/glyphs/freetype_glyphcache.cxx4
-rw-r--r--vcl/unx/generic/printer/ppdparser.cxx7
-rw-r--r--vcl/unx/gtk3/gtk3gtkdata.cxx3
-rw-r--r--vcl/workben/vcldemo.cxx4
-rw-r--r--writerperfect/qa/unit/EPUBExportTest.cxx3
-rw-r--r--writerperfect/source/common/WPXSvInputStream.cxx6
-rw-r--r--xmlhelp/source/treeview/tvread.cxx9
-rw-r--r--xmloff/source/chart/SchXMLTableContext.cxx3
-rw-r--r--xmloff/source/core/attrlist.cxx12
-rw-r--r--xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx5
-rw-r--r--xmloff/source/text/txtlists.cxx5
-rw-r--r--xmlscript/source/xml_helper/xml_element.cxx7
282 files changed, 1202 insertions, 633 deletions
diff --git a/accessibility/source/standard/vclxaccessiblelist.cxx b/accessibility/source/standard/vclxaccessiblelist.cxx
index b549c6d0c008..de2dfc399311 100644
--- a/accessibility/source/standard/vclxaccessiblelist.cxx
+++ b/accessibility/source/standard/vclxaccessiblelist.cxx
@@ -457,7 +457,7 @@ Reference<XAccessible> VCLXAccessibleList::CreateChild (sal_Int32 nPos)
{
Reference<XAccessible> xChild;
- if ( static_cast<size_t>(nPos) >= m_aAccessibleChildren.size() )
+ if ( o3tl::make_unsigned(nPos) >= m_aAccessibleChildren.size() )
{
m_aAccessibleChildren.resize(nPos + 1);
diff --git a/accessibility/source/standard/vclxaccessibletabcontrol.cxx b/accessibility/source/standard/vclxaccessibletabcontrol.cxx
index c88d8d427321..d65e74b242e3 100644
--- a/accessibility/source/standard/vclxaccessibletabcontrol.cxx
+++ b/accessibility/source/standard/vclxaccessibletabcontrol.cxx
@@ -24,6 +24,7 @@
#include <com/sun/star/accessibility/AccessibleRole.hpp>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <o3tl/safeint.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <vcl/tabctrl.hxx>
#include <vcl/tabpage.hxx>
@@ -354,7 +355,7 @@ Reference< XAccessible > VCLXAccessibleTabControl::getAccessibleChild( sal_Int32
{
OExternalLockGuard aGuard( this );
- if ( i < 0 || static_cast<std::size_t>(i) >= m_aAccessibleChildren.size() )
+ if ( i < 0 || o3tl::make_unsigned(i) >= m_aAccessibleChildren.size() )
throw IndexOutOfBoundsException();
return implGetAccessibleChild( i );
@@ -402,7 +403,7 @@ void VCLXAccessibleTabControl::selectAccessibleChild( sal_Int32 nChildIndex )
{
OExternalLockGuard aGuard( this );
- if ( nChildIndex < 0 || static_cast<std::size_t>(nChildIndex) >= m_aAccessibleChildren.size() )
+ if ( nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size() )
throw IndexOutOfBoundsException();
if ( m_pTabControl )
@@ -414,7 +415,7 @@ sal_Bool VCLXAccessibleTabControl::isAccessibleChildSelected( sal_Int32 nChildIn
{
OExternalLockGuard aGuard( this );
- if ( nChildIndex < 0 || static_cast<std::size_t>(nChildIndex) >= m_aAccessibleChildren.size() )
+ if ( nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size() )
throw IndexOutOfBoundsException();
return implIsAccessibleChildSelected( nChildIndex );
@@ -476,7 +477,7 @@ void VCLXAccessibleTabControl::deselectAccessibleChild( sal_Int32 nChildIndex )
{
OExternalLockGuard aGuard( this );
- if ( nChildIndex < 0 || static_cast<std::size_t>(nChildIndex) >= m_aAccessibleChildren.size() )
+ if ( nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size() )
throw IndexOutOfBoundsException();
// This method makes no sense in a tab control, and so does nothing.
diff --git a/accessibility/source/standard/vclxaccessibletoolbox.cxx b/accessibility/source/standard/vclxaccessibletoolbox.cxx
index c456b93997b4..762b2a58ba39 100644
--- a/accessibility/source/standard/vclxaccessibletoolbox.cxx
+++ b/accessibility/source/standard/vclxaccessibletoolbox.cxx
@@ -27,6 +27,7 @@
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/lang/XUnoTunnel.hpp>
+#include <o3tl/safeint.hxx>
#include <vcl/toolbox.hxx>
#include <vcl/vclevent.hxx>
#include <comphelper/accessiblewrapper.hxx>
@@ -689,7 +690,7 @@ Reference< XAccessible > SAL_CALL VCLXAccessibleToolBox::getAccessibleChild( sal
comphelper::OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
- if ( (!pToolBox) || i < 0 || static_cast<size_t>(i) >= pToolBox->GetItemCount() )
+ if ( (!pToolBox) || i < 0 || o3tl::make_unsigned(i) >= pToolBox->GetItemCount() )
throw IndexOutOfBoundsException();
Reference< XAccessible > xChild;
@@ -778,7 +779,7 @@ void VCLXAccessibleToolBox::selectAccessibleChild( sal_Int32 nChildIndex )
OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
- if ( (!pToolBox) || nChildIndex < 0 || static_cast<size_t> (nChildIndex) >= pToolBox->GetItemCount() )
+ if ( (!pToolBox) || nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= pToolBox->GetItemCount() )
throw IndexOutOfBoundsException();
pToolBox->ChangeHighlight( nChildIndex );
@@ -788,7 +789,7 @@ sal_Bool VCLXAccessibleToolBox::isAccessibleChildSelected( sal_Int32 nChildIndex
{
OExternalLockGuard aGuard( this );
VclPtr< ToolBox > pToolBox = GetAs< ToolBox >();
- if ( (!pToolBox) || nChildIndex < 0 || static_cast<size_t>(nChildIndex) >= pToolBox->GetItemCount() )
+ if ( (!pToolBox) || nChildIndex < 0 || o3tl::make_unsigned(nChildIndex) >= pToolBox->GetItemCount() )
throw IndexOutOfBoundsException();
if ( pToolBox->GetHighlightItemId() == pToolBox->GetItemId( nChildIndex ) )
diff --git a/avmedia/source/gstreamer/gstframegrabber.cxx b/avmedia/source/gstreamer/gstframegrabber.cxx
index 496a447103ec..0323ec0dbb56 100644
--- a/avmedia/source/gstreamer/gstframegrabber.cxx
+++ b/avmedia/source/gstreamer/gstframegrabber.cxx
@@ -25,7 +25,7 @@
#include <gst/gstbuffer.h>
#include <gst/video/video.h>
#include <gst/video/gstvideosink.h>
-
+#include <o3tl/safeint.hxx>
#include <vcl/graph.hxx>
#include <vcl/BitmapTools.hxx>
@@ -138,7 +138,7 @@ uno::Reference< graphic::XGraphic > SAL_CALL FrameGrabber::grabFrame( double fMe
if( pBuf && nWidth > 0 && nHeight > 0 &&
// sanity check the size
- gst_buffer_get_size( pBuf ) >= static_cast<unsigned>( nWidth * nHeight * 3 )
+ gst_buffer_get_size( pBuf ) >= o3tl::make_unsigned( nWidth * nHeight * 3 )
)
{
sal_uInt8 *pData = nullptr;
diff --git a/avmedia/source/gstreamer/gstplayer.cxx b/avmedia/source/gstreamer/gstplayer.cxx
index 3ded8831b789..bf934235a992 100644
--- a/avmedia/source/gstreamer/gstplayer.cxx
+++ b/avmedia/source/gstreamer/gstplayer.cxx
@@ -30,7 +30,7 @@
#include <math.h>
#include <cppuhelper/supportsservice.hxx>
-
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <rtl/string.hxx>
#include <salhelper/thread.hxx>
@@ -126,7 +126,7 @@ void MissingPluginInstaller::report(
return;
}
std::size_t len = std::strlen(det);
- if (len > sal_uInt32(SAL_MAX_INT32)) {
+ if (len > o3tl::make_unsigned(SAL_MAX_INT32)) {
SAL_WARN("avmedia.gstreamer", "detail string too long");
g_free(det);
return;
diff --git a/basic/source/runtime/runtime.cxx b/basic/source/runtime/runtime.cxx
index a663dbed961f..46879bb6a65e 100644
--- a/basic/source/runtime/runtime.cxx
+++ b/basic/source/runtime/runtime.cxx
@@ -32,7 +32,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/string.hxx>
-
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <tools/wldcrd.hxx>
@@ -2961,7 +2961,7 @@ void SbiRuntime::StepONJUMP( sal_uInt32 nOp1 )
nOp1 &= 0x7FFF;
PushGosub( pCode + 5 * nOp1 );
}
- if( n < 1 || static_cast<sal_uInt32>(n) > nOp1 )
+ if( n < 1 || o3tl::make_unsigned(n) > nOp1 )
n = static_cast<sal_Int16>( nOp1 + 1 );
nOp1 = static_cast<sal_uInt32>( reinterpret_cast<const char*>(pCode) - pImg->GetCode() ) + 5 * --n;
StepJUMP( nOp1 );
diff --git a/basic/source/sbx/sbxarray.cxx b/basic/source/sbx/sbxarray.cxx
index 152ab5a671f4..172311808836 100644
--- a/basic/source/sbx/sbxarray.cxx
+++ b/basic/source/sbx/sbxarray.cxx
@@ -18,7 +18,7 @@
*/
#include <config_features.h>
-
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <basic/sbx.hxx>
@@ -518,7 +518,7 @@ sal_uInt32 SbxDimArray::Offset32( SbxArray* pPar )
if (IsError())
break;
}
- if( nPos > sal_uInt32(SBX_MAXINDEX32) )
+ if( nPos > o3tl::make_unsigned(SBX_MAXINDEX32) )
{
SetError( ERRCODE_BASIC_OUT_OF_RANGE );
nPos = 0;
diff --git a/basic/source/sbx/sbxbyte.cxx b/basic/source/sbx/sbxbyte.cxx
index 6557aa3fff4b..4974213dc7a1 100644
--- a/basic/source/sbx/sbxbyte.cxx
+++ b/basic/source/sbx/sbxbyte.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <vcl/errcode.hxx>
//#include <basic/sbx.hxx>
#include <basic/sberrors.hxx>
@@ -61,7 +64,7 @@ start:
break;
case SbxERROR:
case SbxUSHORT:
- if( p->nUShort > sal_uInt16(SbxMAXBYTE) )
+ if( p->nUShort > o3tl::make_unsigned(SbxMAXBYTE) )
{
SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXBYTE;
}
diff --git a/basic/source/sbx/sbxint.cxx b/basic/source/sbx/sbxint.cxx
index 2ba76c89e352..a28b810eb8c7 100644
--- a/basic/source/sbx/sbxint.cxx
+++ b/basic/source/sbx/sbxint.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <o3tl/float_int_conversion.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/errcode.hxx>
#include <basic/sberrors.hxx>
#include "sbxconv.hxx"
@@ -47,7 +48,7 @@ start:
nRes = p->nInteger; break;
case SbxERROR:
case SbxUSHORT:
- if( p->nUShort > sal_uInt16(SbxMAXINT) )
+ if( p->nUShort > o3tl::make_unsigned(SbxMAXINT) )
{
SbxBase::SetError( ERRCODE_BASIC_MATH_OVERFLOW ); nRes = SbxMAXINT;
}
diff --git a/binaryurp/source/bridgefactory.cxx b/binaryurp/source/bridgefactory.cxx
index 350e9a77df26..be21fc9c6b40 100644
--- a/binaryurp/source/bridgefactory.cxx
+++ b/binaryurp/source/bridgefactory.cxx
@@ -33,6 +33,7 @@
#include <cppuhelper/factory.hxx>
#include <cppuhelper/implementationentry.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ref.hxx>
#include <sal/log.hxx>
#include <sal/types.h>
@@ -150,7 +151,7 @@ BridgeFactory::getExistingBridges() {
static_cast< cppu::OWeakObject * >(this));
}
sal_Int32 n = static_cast< sal_Int32 >(unnamed_.size());
- if (named_.size() > static_cast< sal_uInt32 >(SAL_MAX_INT32 - n)) {
+ if (named_.size() > o3tl::make_unsigned(SAL_MAX_INT32 - n)) {
throw css::uno::RuntimeException(
"BridgeFactory::getExistingBridges: too many",
static_cast< cppu::OWeakObject * >(this));
diff --git a/chart2/source/controller/accessibility/AccessibleBase.cxx b/chart2/source/controller/accessibility/AccessibleBase.cxx
index 26657d429bd1..840f578aa17a 100644
--- a/chart2/source/controller/accessibility/AccessibleBase.cxx
+++ b/chart2/source/controller/accessibility/AccessibleBase.cxx
@@ -42,6 +42,7 @@
#include <vcl/window.hxx>
#include <vcl/settings.hxx>
#include <o3tl/functional.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
#include <unotools/accessiblestatesethelper.hxx>
@@ -503,7 +504,7 @@ Reference< XAccessible > AccessibleBase::ImplGetAccessibleChildById( sal_Int32 i
MutexGuard aGuard( m_aMutex);
if( ! m_bMayHaveChildren ||
i < 0 ||
- static_cast< ChildListVectorType::size_type >( i ) >= m_aChildList.size() )
+ o3tl::make_unsigned( i ) >= m_aChildList.size() )
{
OUString aBuf = "Index " + OUString::number( i ) + " is invalid for range [ 0, " +
OUString::number( m_aChildList.size() - 1 ) +
diff --git a/chart2/source/controller/dialogs/DataBrowser.cxx b/chart2/source/controller/dialogs/DataBrowser.cxx
index cbfb03b50031..465496f62979 100644
--- a/chart2/source/controller/dialogs/DataBrowser.cxx
+++ b/chart2/source/controller/dialogs/DataBrowser.cxx
@@ -36,6 +36,7 @@
#include <vcl/svapp.hxx>
#include <vcl/virdev.hxx>
#include <rtl/math.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <toolkit/helper/vclunohelper.hxx>
@@ -570,7 +571,7 @@ bool DataBrowser::MayMoveLeftColumns() const
{
sal_Int32 nColIndex(0);
if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex ))
- return (static_cast< sal_uInt32 >( nColIndex ) <= (m_aSeriesHeaders.size() - 1)) && (static_cast< sal_uInt32 >( nColIndex ) != 0);
+ return (o3tl::make_unsigned( nColIndex ) <= (m_aSeriesHeaders.size() - 1)) && (static_cast< sal_uInt32 >( nColIndex ) != 0);
}
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders );
@@ -587,7 +588,7 @@ bool DataBrowser::MayMoveRightColumns() const
{
sal_Int32 nColIndex(0);
if( lcl_SeriesHeaderHasFocus( m_aSeriesHeaders, &nColIndex ))
- return (static_cast< sal_uInt32 >( nColIndex ) < (m_aSeriesHeaders.size() - 1));
+ return (o3tl::make_unsigned( nColIndex ) < (m_aSeriesHeaders.size() - 1));
}
sal_Int32 nColIdx = lcl_getColumnInDataOrHeader( GetCurColumnId(), m_aSeriesHeaders );
diff --git a/chart2/source/controller/dialogs/DataBrowserModel.cxx b/chart2/source/controller/dialogs/DataBrowserModel.cxx
index 272693f1d7c6..e353899eb81e 100644
--- a/chart2/source/controller/dialogs/DataBrowserModel.cxx
+++ b/chart2/source/controller/dialogs/DataBrowserModel.cxx
@@ -41,6 +41,7 @@
#include <com/sun/star/chart2/data/XNumericalDataSequence.hpp>
#include <com/sun/star/chart2/data/XTextualDataSequence.hpp>
#include <com/sun/star/util/XModifiable.hpp>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
#include <comphelper/property.hxx>
@@ -291,7 +292,7 @@ void DataBrowserModel::insertDataSeries( sal_Int32 nAfterColumnIndex )
Reference<chart2::XDiagram> xDiagram = ChartModelHelper::findDiagram(m_xChartDocument);
Reference<chart2::XChartType> xChartType;
Reference<chart2::XDataSeries> xSeries;
- if (static_cast<size_t>(nAfterColumnIndex) < m_aColumns.size())
+ if (o3tl::make_unsigned(nAfterColumnIndex) < m_aColumns.size())
// Get the data series at specific column position (if available).
xSeries.set( m_aColumns[nAfterColumnIndex].m_xDataSeries );
@@ -436,7 +437,7 @@ void DataBrowserModel::removeComplexCategoryLevel( sal_Int32 nAtColumnIndex )
void DataBrowserModel::removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColumnIndex )
{
OSL_ASSERT(m_apDialogModel);
- if (nAtColumnIndex < 0 || static_cast<size_t>(nAtColumnIndex) >= m_aColumns.size())
+ if (nAtColumnIndex < 0 || o3tl::make_unsigned(nAtColumnIndex) >= m_aColumns.size())
// Out of bound.
return;
@@ -505,7 +506,7 @@ void DataBrowserModel::removeDataSeriesOrComplexCategoryLevel( sal_Int32 nAtColu
void DataBrowserModel::swapDataSeries( sal_Int32 nFirstColumnIndex )
{
OSL_ASSERT(m_apDialogModel);
- if( static_cast< tDataColumnVector::size_type >( nFirstColumnIndex ) < m_aColumns.size() - 1 )
+ if( o3tl::make_unsigned( nFirstColumnIndex ) < m_aColumns.size() - 1 )
{
Reference< chart2::XDataSeries > xSeries( m_aColumns[nFirstColumnIndex].m_xDataSeries );
if( xSeries.is())
@@ -728,7 +729,7 @@ sal_Int32 DataBrowserModel::getMaxRowCount() const
OUString DataBrowserModel::getRoleOfColumn( sal_Int32 nColumnIndex ) const
{
if( nColumnIndex != -1 &&
- static_cast< sal_uInt32 >( nColumnIndex ) < m_aColumns.size())
+ o3tl::make_unsigned( nColumnIndex ) < m_aColumns.size())
return m_aColumns[ nColumnIndex ].m_aUIRoleName;
return OUString();
}
@@ -738,7 +739,7 @@ bool DataBrowserModel::isCategoriesColumn( sal_Int32 nColumnIndex ) const
if (nColumnIndex < 0)
return false;
- if (static_cast<size_t>(nColumnIndex) >= m_aColumns.size())
+ if (o3tl::make_unsigned(nColumnIndex) >= m_aColumns.size())
return false;
// A column is a category when it doesn't have an associated data series.
diff --git a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
index 7113eba8857b..9259ce921819 100644
--- a/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
+++ b/chart2/source/controller/drawinglayer/ViewElementListProvider.cxx
@@ -24,7 +24,7 @@
#include <DrawViewWrapper.hxx>
#include <com/sun/star/drawing/Direction3D.hpp>
-
+#include <o3tl/safeint.hxx>
#include <svx/xtable.hxx>
#include <svl/itempool.hxx>
#include <svtools/ctrltool.hxx>
@@ -141,7 +141,7 @@ Graphic ViewElementListProvider::GetSymbolGraphic( sal_Int32 nStandardSymbol, co
return Graphic();
if(nStandardSymbol<0)
nStandardSymbol*=-1;
- if( static_cast<size_t>(nStandardSymbol) >= pSymbolList->GetObjCount() )
+ if( o3tl::make_unsigned(nStandardSymbol) >= pSymbolList->GetObjCount() )
nStandardSymbol %= pSymbolList->GetObjCount();
SdrObject* pObj = pSymbolList->GetObj(nStandardSymbol);
diff --git a/chart2/source/controller/main/ElementSelector.cxx b/chart2/source/controller/main/ElementSelector.cxx
index 8ff8f2039abe..4cc61cc1d1b0 100644
--- a/chart2/source/controller/main/ElementSelector.cxx
+++ b/chart2/source/controller/main/ElementSelector.cxx
@@ -27,6 +27,7 @@
#include <ObjectIdentifier.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/svapp.hxx>
@@ -182,7 +183,7 @@ void SelectorListBox::Select()
if ( !IsTravelSelect() )
{
const sal_Int32 nPos = GetSelectedEntryPos();
- if( static_cast<size_t>(nPos) < m_aEntries.size() )
+ if( o3tl::make_unsigned(nPos) < m_aEntries.size() )
{
ObjectIdentifier aOID = m_aEntries[nPos].OID;
Reference< view::XSelectionSupplier > xSelectionSupplier( m_xChartController.get(), uno::UNO_QUERY );
diff --git a/chart2/source/model/main/BaseCoordinateSystem.cxx b/chart2/source/model/main/BaseCoordinateSystem.cxx
index a343cc614a91..7075f2ed6f26 100644
--- a/chart2/source/model/main/BaseCoordinateSystem.cxx
+++ b/chart2/source/model/main/BaseCoordinateSystem.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/chart2/AxisType.hpp>
#include <com/sun/star/container/NoSuchElementException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
#include <algorithm>
@@ -196,7 +197,7 @@ void SAL_CALL BaseCoordinateSystem::setAxisByDimension(
if( nIndex < 0 )
throw lang::IndexOutOfBoundsException();
- if( m_aAllAxis[ nDimensionIndex ].size() < static_cast< tAxisVecVecType::size_type >( nIndex+1 ))
+ if( m_aAllAxis[ nDimensionIndex ].size() < o3tl::make_unsigned( nIndex+1 ))
{
m_aAllAxis[ nDimensionIndex ].resize( nIndex+1 );
m_aAllAxis[ nDimensionIndex ][nIndex] = nullptr;
diff --git a/chart2/source/tools/ExplicitCategoriesProvider.cxx b/chart2/source/tools/ExplicitCategoriesProvider.cxx
index 46036e5b9d3f..845b55afda04 100644
--- a/chart2/source/tools/ExplicitCategoriesProvider.cxx
+++ b/chart2/source/tools/ExplicitCategoriesProvider.cxx
@@ -28,6 +28,7 @@
#include <unonames.hxx>
#include <com/sun/star/chart2/AxisType.hpp>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
namespace chart
@@ -360,7 +361,7 @@ static Sequence< OUString > lcl_getExplicitSimpleCategories(
OUStringBuffer aText;
for (auto const& complexCatPerIndex : aComplexCatsPerIndex)
{
- if ( static_cast<size_t>(nN) < complexCatPerIndex.size() )
+ if ( o3tl::make_unsigned(nN) < complexCatPerIndex.size() )
{
OUString aAddText = complexCatPerIndex[nN].Text;
if( !aAddText.isEmpty() )
diff --git a/chart2/source/view/axes/Tickmarks_Equidistant.hxx b/chart2/source/view/axes/Tickmarks_Equidistant.hxx
index 4c89d4b44251..55263c05ba28 100644
--- a/chart2/source/view/axes/Tickmarks_Equidistant.hxx
+++ b/chart2/source/view/axes/Tickmarks_Equidistant.hxx
@@ -22,6 +22,8 @@
#include "Tickmarks.hxx"
#include <memory>
+#include <o3tl/safeint.hxx>
+
namespace chart
{
@@ -58,7 +60,7 @@ private: //methods
return (*m_pSimpleTicks)[nDepth][nIndex];
else
{
- if ((*m_pInfoTicks)[nDepth].size() <= size_t(nIndex))
+ if ((*m_pInfoTicks)[nDepth].size() <= o3tl::make_unsigned(nIndex))
return std::numeric_limits<double>::max();
return (((*m_pInfoTicks)[nDepth])[nIndex]).fScaledTickValue;
}
diff --git a/comphelper/source/eventattachermgr/eventattachermgr.cxx b/comphelper/source/eventattachermgr/eventattachermgr.cxx
index 6651c6033bb6..9d7561fc9ef9 100644
--- a/comphelper/source/eventattachermgr/eventattachermgr.cxx
+++ b/comphelper/source/eventattachermgr/eventattachermgr.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <osl/diagnose.h>
#include <comphelper/eventattachermgr.hxx>
@@ -377,7 +378,7 @@ Reference< XIdlReflection > ImplEventAttacherManager::getReflection()
std::deque< AttacherIndex_Impl >::iterator ImplEventAttacherManager::implCheckIndex( sal_Int32 _nIndex )
{
- if ( (_nIndex < 0) || (static_cast<sal_uInt32>(_nIndex) >= aIndex.size()) )
+ if ( (_nIndex < 0) || (o3tl::make_unsigned(_nIndex) >= aIndex.size()) )
throw IllegalArgumentException();
std::deque<AttacherIndex_Impl>::iterator aIt = aIndex.begin() + _nIndex;
@@ -498,7 +499,7 @@ void SAL_CALL ImplEventAttacherManager::insertEntry(sal_Int32 nIndex)
if( nIndex < 0 )
throw IllegalArgumentException();
- if ( static_cast< std::deque< AttacherIndex_Impl >::size_type>(nIndex) >= aIndex.size() )
+ if ( o3tl::make_unsigned(nIndex) >= aIndex.size() )
aIndex.resize(nIndex+1);
AttacherIndex_Impl aTmp;
@@ -533,7 +534,7 @@ void SAL_CALL ImplEventAttacherManager::attach(sal_Int32 nIndex, const Reference
if( nIndex < 0 || !xObject.is() )
throw IllegalArgumentException();
- if( static_cast< std::deque< AttacherIndex_Impl >::size_type>(nIndex) >= aIndex.size() )
+ if( o3tl::make_unsigned(nIndex) >= aIndex.size() )
{
// read older files
if( nVersion != 1 )
@@ -587,7 +588,7 @@ void SAL_CALL ImplEventAttacherManager::detach(sal_Int32 nIndex, const Reference
{
Guard< Mutex > aGuard( aLock );
//return;
- if( nIndex < 0 || static_cast< std::deque< AttacherIndex_Impl >::size_type>(nIndex) >= aIndex.size() || !xObject.is() )
+ if( nIndex < 0 || o3tl::make_unsigned(nIndex) >= aIndex.size() || !xObject.is() )
throw IllegalArgumentException();
std::deque< AttacherIndex_Impl >::iterator aCurrentPosition = aIndex.begin() + nIndex;
diff --git a/comphelper/source/streaming/oslfile2streamwrap.cxx b/comphelper/source/streaming/oslfile2streamwrap.cxx
index 14441d61f76f..eff916a833ff 100644
--- a/comphelper/source/streaming/oslfile2streamwrap.cxx
+++ b/comphelper/source/streaming/oslfile2streamwrap.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/io/BufferSizeExceededException.hpp>
#include <com/sun/star/io/NotConnectedException.hpp>
#include <comphelper/oslfile2streamwrap.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <algorithm>
@@ -60,7 +61,7 @@ sal_Int32 SAL_CALL OSLInputStreamWrapper::readBytes(css::uno::Sequence< sal_Int8
throw css::io::BufferSizeExceededException(OUString(),static_cast<css::uno::XWeak*>(this));
// If the read character < MaxLength, adjust css::uno::Sequence
- if (nRead < static_cast<sal_uInt32>(nBytesToRead))
+ if (nRead < o3tl::make_unsigned(nBytesToRead))
aData.realloc( sal::static_int_cast< sal_Int32 >(nRead) );
return sal::static_int_cast< sal_Int32 >(nRead);
diff --git a/compilerplugins/clang/test/unsignedcompare.cxx b/compilerplugins/clang/test/unsignedcompare.cxx
new file mode 100644
index 000000000000..32b9af8138a0
--- /dev/null
+++ b/compilerplugins/clang/test/unsignedcompare.cxx
@@ -0,0 +1,16 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+bool f(int i1, unsigned i2)
+{
+ // expected-error@+1 {{explicit cast from 'int' to 'unsigned int' (of equal rank) in comparison against 'unsigned int': if the cast value is known to be non-negative, use o3tl::make_unsigned instead of the cast [loplugin:unsignedcompare]}}
+ return unsigned(i1) < i2;
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/compilerplugins/clang/unsignedcompare.cxx b/compilerplugins/clang/unsignedcompare.cxx
new file mode 100644
index 000000000000..beac09f07f7d
--- /dev/null
+++ b/compilerplugins/clang/unsignedcompare.cxx
@@ -0,0 +1,231 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4; fill-column: 100 -*- */
+/*
+ * This file is part of the LibreOffice project.
+ *
+ * This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/.
+ */
+
+// Find explicit casts from signed to unsigned integer in comparison against unsigned integer, where
+// the cast is presumably used to avoid warnings about signed vs. unsigned comparisons, and could
+// thus be replaced with o3tl::make_unsigned for clairty.
+
+#include <cassert>
+
+#include "config_clang.h"
+
+#include "compat.hxx"
+#include "plugin.hxx"
+
+namespace
+{
+// clang::Type::isSignedIntegerType returns true for more types than what C++ defines as signed
+// integer types:
+bool isSignedIntegerType(QualType type)
+{
+ if (auto const t = type->getAs<BuiltinType>())
+ {
+ // Assumes that the only extended signed integer type supported by Clang is Int128:
+ switch (t->getKind())
+ {
+ case BuiltinType::SChar:
+ case BuiltinType::Short:
+ case BuiltinType::Int:
+ case BuiltinType::Long:
+ case BuiltinType::LongLong:
+ case BuiltinType::Int128:
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+// clang::Type::isUnsignedIntegerType returns true for more types than what C++ defines as signed
+// integer types:
+bool isUnsignedIntegerType(QualType type)
+{
+ if (auto const t = type->getAs<BuiltinType>())
+ {
+ // Assumes that the only extended unsigned integer type supported by Clang is UInt128:
+ switch (t->getKind())
+ {
+ case BuiltinType::UChar:
+ case BuiltinType::UShort:
+ case BuiltinType::UInt:
+ case BuiltinType::ULong:
+ case BuiltinType::ULongLong:
+ case BuiltinType::UInt128:
+ return true;
+ default:
+ break;
+ }
+ }
+ return false;
+}
+
+int getRank(QualType type)
+{
+ auto const t = type->getAs<BuiltinType>();
+ assert(t != nullptr);
+ // Assumes that the only extended signed/unsigned integer types supported by Clang are Int128
+ // and UInt128:
+ switch (t->getKind())
+ {
+ case BuiltinType::SChar:
+ case BuiltinType::UChar:
+ return 0;
+ case BuiltinType::Short:
+ case BuiltinType::UShort:
+ return 1;
+ case BuiltinType::Int:
+ case BuiltinType::UInt:
+ return 2;
+ case BuiltinType::Long:
+ case BuiltinType::ULong:
+ return 3;
+ case BuiltinType::LongLong:
+ case BuiltinType::ULongLong:
+ return 4;
+ case BuiltinType::Int128:
+ case BuiltinType::UInt128:
+ return 5;
+ default:
+ llvm_unreachable("bad integer type");
+ }
+}
+
+int orderTypes(QualType type1, QualType type2)
+{
+ auto const r1 = getRank(type1);
+ auto const r2 = getRank(type2);
+ return r1 < r2 ? -1 : r1 == r2 ? 0 : 1;
+}
+
+class UnsignedCompare : public loplugin::FilteringPlugin<UnsignedCompare>
+{
+public:
+ explicit UnsignedCompare(loplugin::InstantiationData const& data)
+ : FilteringPlugin(data)
+ {
+ }
+
+ bool VisitBinaryOperator(BinaryOperator const* expr)
+ {
+ if (ignoreLocation(expr))
+ {
+ return true;
+ }
+ // o3tl::make_unsigned requires its argument to be non-negative, but this plugin doesn't
+ // check that when it reports its finding, so will produce false positives when the cast is
+ // actually meant to e.g. clamp from a large signed type to a small unsigned type. The
+ // assumption is that this will only be likely the case for BO_EQ (==) and BO_NE (!=)
+ // comparisons, so filter these out here (not sure what case BO_Cmp (<=>) will turn out to
+ // be, so lets keep it here at least for now):
+ switch (expr->getOpcode())
+ {
+#if CLANG_VERSION >= 60000
+ case BO_Cmp:
+#endif
+ case BO_LT:
+ case BO_GT:
+ case BO_LE:
+ case BO_GE:
+ break;
+ default:
+ return true;
+ }
+ auto const castL = isCastToUnsigned(expr->getLHS());
+ auto const castR = isCastToUnsigned(expr->getRHS());
+ //TODO(?): Also report somewhat suspicious cases where both sides are cast to unsigned:
+ if ((castL == nullptr) == (castR == nullptr))
+ {
+ return true;
+ }
+ auto const cast = castL != nullptr ? castL : castR;
+ auto const other = castL != nullptr ? expr->getRHS() : expr->getLHS();
+ auto const otherT = other->IgnoreImpCasts()->getType();
+ if (!isUnsignedIntegerType(otherT))
+ {
+ return true;
+ }
+ auto const castFromT = cast->getSubExprAsWritten()->getType();
+ auto const castToT = cast->getTypeAsWritten();
+ report(DiagnosticsEngine::Warning,
+ "explicit cast from %0 to %1 (of %select{smaller|equal|larger}2 rank) in comparison "
+ "against %3: if the cast value is known to be non-negative, use o3tl::make_unsigned "
+ "instead of the cast",
+ cast->getExprLoc())
+ << castFromT << castToT << (orderTypes(castToT, castFromT) + 1) << otherT
+ << expr->getSourceRange();
+ return true;
+ }
+
+private:
+ bool preRun() override
+ {
+ return compiler.getLangOpts().CPlusPlus
+ && compiler.getPreprocessor()
+ .getIdentifierInfo("LIBO_INTERNAL_ONLY")
+ ->hasMacroDefinition();
+ }
+
+ void run() override
+ {
+ if (preRun())
+ {
+ TraverseDecl(compiler.getASTContext().getTranslationUnitDecl());
+ }
+ }
+
+ ExplicitCastExpr const* isCastToUnsigned(Expr const* expr)
+ {
+ auto const e = dyn_cast<ExplicitCastExpr>(expr->IgnoreParenImpCasts());
+ if (e == nullptr)
+ {
+ return nullptr;
+ }
+ auto const t1 = e->getTypeAsWritten();
+ if (!isUnsignedIntegerType(t1))
+ {
+ return nullptr;
+ }
+ auto const e2 = e->getSubExprAsWritten();
+ auto const t2 = e2->getType();
+ if (!isSignedIntegerType(t2))
+ {
+ return nullptr;
+ }
+ // Filter out e.g. `size_t(-1)`:
+ APSInt val;
+ if (!e2->isValueDependent() && e2->isIntegerConstantExpr(val, compiler.getASTContext()))
+ {
+ if (val.isNegative())
+ {
+ return nullptr;
+ }
+ }
+ auto loc = compat::getBeginLoc(e);
+ while (compiler.getSourceManager().isMacroArgExpansion(loc))
+ {
+ loc = compiler.getSourceManager().getImmediateMacroCallerLoc(loc);
+ }
+ // This covers both "plain" code in such include files, as well as expansion of (object-like) macros like
+ //
+ // #define SAL_MAX_INT8 ((sal_Int8) 0x7F)
+ //
+ // defined in such include files:
+ if (isInUnoIncludeFile(compiler.getSourceManager().getSpellingLoc(loc)))
+ { //TODO: '#ifdef LIBO_INTERNAL_ONLY' within UNO include files
+ return nullptr;
+ }
+ return e;
+ }
+};
+
+loplugin::Plugin::Registration<UnsignedCompare> unsignedcompare("unsignedcompare");
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */
diff --git a/configmgr/source/dconf.cxx b/configmgr/source/dconf.cxx
index 430dc37cc071..8493b3351e83 100644
--- a/configmgr/source/dconf.cxx
+++ b/configmgr/source/dconf.cxx
@@ -14,7 +14,6 @@
#include <cstring>
#include <forward_list>
#include <limits>
-#include <type_traits>
#include <vector>
extern "C" {
@@ -24,6 +23,7 @@ extern "C" {
}
#include <com/sun/star/uno/Sequence.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -322,7 +322,7 @@ bool getStringValue(
}
gsize n;
char const * p = g_variant_get_string(variant.get(), &n);
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long string value for key " << key);
@@ -366,7 +366,7 @@ bool getHexbinaryValue(
gsize n;
gconstpointer p = g_variant_get_fixed_array(
variant.get(), &n, sizeof (guchar));
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long hexbinary value for key " << key);
@@ -404,7 +404,7 @@ bool getBooleanList(
gsize n;
gconstpointer p = g_variant_get_fixed_array(
variant.get(), &n, sizeof (guchar));
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long boolean list for key " << key);
@@ -431,7 +431,7 @@ bool getShortList(
gsize n;
gconstpointer p = g_variant_get_fixed_array(
variant.get(), &n, sizeof (gint16));
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long short list for key " << key);
@@ -458,7 +458,7 @@ bool getIntList(
gsize n;
gconstpointer p = g_variant_get_fixed_array(
variant.get(), &n, sizeof (gint32));
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long int list for key " << key);
@@ -485,7 +485,7 @@ bool getLongList(
gsize n;
gconstpointer p = g_variant_get_fixed_array(
variant.get(), &n, sizeof (gint64));
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long long list for key " << key);
@@ -512,7 +512,7 @@ bool getDoubleList(
gsize n;
gconstpointer p = g_variant_get_fixed_array(
variant.get(), &n, sizeof (gdouble));
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long double list for key " << key);
@@ -537,7 +537,7 @@ bool getStringList(
return false;
}
gsize n = g_variant_n_children(variant.get());
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long string list for key " << key);
@@ -565,7 +565,7 @@ bool getHexbinaryList(
return false;
}
gsize n = g_variant_n_children(variant.get());
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long hexbinary list for key " << key);
@@ -765,7 +765,7 @@ void readDir(
StringArrayHolder a(dconf_client_list(client.get(), dir.getStr(), nullptr));
for (char const * const * p = a.get(); *p != nullptr; ++p) {
std::size_t n = std::strlen(*p);
- if (n > static_cast<typename std::make_unsigned<sal_Int32>::type>(
+ if (n > o3tl::make_unsigned(
std::numeric_limits<sal_Int32>::max()))
{
SAL_WARN("configmgr.dconf", "too long dir/key in dir " << dir);
diff --git a/configmgr/source/writemodfile.cxx b/configmgr/source/writemodfile.cxx
index 017e925dee48..22fd43ecf797 100644
--- a/configmgr/source/writemodfile.cxx
+++ b/configmgr/source/writemodfile.cxx
@@ -27,6 +27,7 @@
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/RuntimeException.hpp>
#include <com/sun/star/uno/Sequence.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.h>
#include <osl/file.hxx>
#include <rtl/string.h>
@@ -58,7 +59,7 @@ namespace {
OString convertToUtf8(std::u16string_view text) {
OString s;
- assert(text.size() <= sal_uInt32(std::numeric_limits<sal_Int32>::max()));
+ assert(text.size() <= o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max()));
if (!rtl_convertUStringToString(
&s.pData, text.data(), text.size(),
RTL_TEXTENCODING_UTF8,
diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx
index 629c5cd074e2..9d4dcd18106d 100644
--- a/connectivity/source/commontools/dbtools.cxx
+++ b/connectivity/source/commontools/dbtools.cxx
@@ -75,6 +75,7 @@
#include <connectivity/dbtools.hxx>
#include <connectivity/statementcomposer.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -1659,7 +1660,7 @@ namespace
{
if ( m_aSet.empty() )
return m_xSource->getByIndex(Index);
- if ( m_aSet.size() < static_cast<size_t>(Index) )
+ if ( Index < 0 || m_aSet.size() < o3tl::make_unsigned(Index) )
throw IndexOutOfBoundsException();
std::vector<bool, std::allocator<bool> >::const_iterator aIter = m_aSet.begin();
diff --git a/connectivity/source/commontools/parameters.cxx b/connectivity/source/commontools/parameters.cxx
index f7a2d73e109b..6397ea6f783d 100644
--- a/connectivity/source/commontools/parameters.cxx
+++ b/connectivity/source/commontools/parameters.cxx
@@ -36,6 +36,7 @@
#include <tools/diagnose_ex.h>
#include <connectivity/ParameterCont.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -468,7 +469,7 @@ namespace dbtools
size_t nAlreadyVisited = 0;
for (auto & aIndex : aParam.second.aInnerIndexes)
{
- if ( ( m_aParametersVisited.size() > static_cast<size_t>(aIndex) ) && m_aParametersVisited[ aIndex ] )
+ if ( ( m_aParametersVisited.size() > o3tl::make_unsigned(aIndex) ) && m_aParametersVisited[ aIndex ] )
{ // exclude this index
aIndex = -1;
++nAlreadyVisited;
@@ -949,7 +950,7 @@ namespace dbtools
void ParameterManager::externalParameterVisited( sal_Int32 _nIndex )
{
- if ( m_aParametersVisited.size() < static_cast<size_t>(_nIndex) )
+ if ( m_aParametersVisited.size() < o3tl::make_unsigned(_nIndex) )
{
m_aParametersVisited.reserve( _nIndex );
for ( sal_Int32 i = m_aParametersVisited.size(); i < _nIndex; ++i )
diff --git a/connectivity/source/drivers/dbase/DTable.cxx b/connectivity/source/drivers/dbase/DTable.cxx
index 06d0fdf7d576..5fc64ab84625 100644
--- a/connectivity/source/drivers/dbase/DTable.cxx
+++ b/connectivity/source/drivers/dbase/DTable.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/sdbc/DataType.hpp>
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <com/sun/star/sdbc/XRow.hpp>
+#include <o3tl/safeint.hxx>
#include <svl/converter.hxx>
#include <dbase/DConnection.hxx>
#include <dbase/DColumns.hxx>
@@ -848,7 +849,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool
else if ( DataType::INTEGER == nType )
{
sal_Int32 nValue = 0;
- if (static_cast<size_t>(nLen) > sizeof(nValue))
+ if (o3tl::make_unsigned(nLen) > sizeof(nValue))
return false;
memcpy(&nValue, pData, nLen);
*(_rRow->get())[i] = nValue;
@@ -859,7 +860,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool
if (getBOOL((*aIter)->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency is treated separately
{
sal_Int64 nValue = 0;
- if (static_cast<size_t>(nLen) > sizeof(nValue))
+ if (o3tl::make_unsigned(nLen) > sizeof(nValue))
return false;
memcpy(&nValue, pData, nLen);
@@ -870,7 +871,7 @@ bool ODbaseTable::fetchRow(OValueRefRow& _rRow, const OSQLColumns & _rCols, bool
}
else
{
- if (static_cast<size_t>(nLen) > sizeof(d))
+ if (o3tl::make_unsigned(nLen) > sizeof(d))
return false;
memcpy(&d, pData, nLen);
}
@@ -1697,11 +1698,11 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
{
// Lengths for each data type:
assert(i >= 0);
- OSL_ENSURE(sal_uInt32(i) < m_aPrecisions.size(),"Illegal index!");
+ OSL_ENSURE(o3tl::make_unsigned(i) < m_aPrecisions.size(),"Illegal index!");
sal_Int32 nLen = 0;
sal_Int32 nType = 0;
sal_Int32 nScale = 0;
- if ( sal_uInt32(i) < m_aPrecisions.size() )
+ if ( o3tl::make_unsigned(i) < m_aPrecisions.size() )
{
nLen = m_aPrecisions[i];
nType = m_aTypes[i];
@@ -1832,7 +1833,7 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
case DataType::INTEGER:
{
sal_Int32 nValue = thisColVal;
- if (static_cast<size_t>(nLen) > sizeof(nValue))
+ if (o3tl::make_unsigned(nLen) > sizeof(nValue))
return false;
memcpy(pData,&nValue,nLen);
}
@@ -1849,13 +1850,13 @@ bool ODbaseTable::UpdateBuffer(OValueRefVector& rRow, const OValueRefRow& pOrgRo
nValue = static_cast<sal_Int64>(d * pow(10.0,static_cast<int>(m_aScales[i])));
else
nValue = static_cast<sal_Int64>(d);
- if (static_cast<size_t>(nLen) > sizeof(nValue))
+ if (o3tl::make_unsigned(nLen) > sizeof(nValue))
return false;
memcpy(pData,&nValue,nLen);
} // if (getBOOL(xCol->getPropertyValue(OMetaConnection::getPropMap().getNameByIndex(PROPERTY_ID_ISCURRENCY)))) // Currency is treated separately
else
{
- if (static_cast<size_t>(nLen) > sizeof(d))
+ if (o3tl::make_unsigned(nLen) > sizeof(d))
return false;
memcpy(pData,&d,nLen);
}
diff --git a/connectivity/source/drivers/dbase/dindexnode.cxx b/connectivity/source/drivers/dbase/dindexnode.cxx
index 43db753bdaf9..4b1c24057020 100644
--- a/connectivity/source/drivers/dbase/dindexnode.cxx
+++ b/connectivity/source/drivers/dbase/dindexnode.cxx
@@ -19,6 +19,7 @@
#include <dbase/dindexnode.hxx>
#include <dbase/DIndex.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <sal/log.hxx>
@@ -245,7 +246,7 @@ bool ONDXPage::Insert(ONDXNode& rNode, sal_uInt32 nRowsLeft)
// How many nodes are being inserted?
// Enough, then we can fill the page to the brim
ONDXNode aInnerNode;
- if (!IsLeaf() || nRowsLeft < static_cast<sal_uInt32>(rIndex.GetMaxNodes() / 2))
+ if (!IsLeaf() || nRowsLeft < o3tl::make_unsigned(rIndex.GetMaxNodes() / 2))
aInnerNode = Split(*aNewPage);
else
{
diff --git a/connectivity/source/drivers/file/FStatement.cxx b/connectivity/source/drivers/file/FStatement.cxx
index 8e25a34dac88..a3fd14970b22 100644
--- a/connectivity/source/drivers/file/FStatement.cxx
+++ b/connectivity/source/drivers/file/FStatement.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <file/FStatement.hxx>
#include <file/FConnection.hxx>
@@ -606,7 +609,7 @@ void OStatement_Base::GetAssignValues()
void OStatement_Base::ParseAssignValues(const std::vector< OUString>& aColumnNameList,OSQLParseNode* pRow_Value_Constructor_Elem, sal_Int32 nIndex)
{
- OSL_ENSURE(size_t(nIndex) <= aColumnNameList.size(),"SdbFileCursor::ParseAssignValues: nIndex > aColumnNameList.GetTokenCount()");
+ OSL_ENSURE(o3tl::make_unsigned(nIndex) <= aColumnNameList.size(),"SdbFileCursor::ParseAssignValues: nIndex > aColumnNameList.GetTokenCount()");
OUString aColumnName(aColumnNameList[nIndex]);
OSL_ENSURE(aColumnName.getLength() > 0,"OResultSet: Column-Name not found");
OSL_ENSURE(pRow_Value_Constructor_Elem != nullptr,"OResultSet: pRow_Value_Constructor_Elem must not be NULL!");
diff --git a/connectivity/source/drivers/flat/ETable.cxx b/connectivity/source/drivers/flat/ETable.cxx
index 142d191be8c9..6d9fc203f950 100644
--- a/connectivity/source/drivers/flat/ETable.cxx
+++ b/connectivity/source/drivers/flat/ETable.cxx
@@ -24,6 +24,7 @@
#include <com/sun/star/ucb/XContentAccess.hpp>
#include <flat/EConnection.hxx>
#include <flat/EColumns.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/math.hxx>
#include <sal/log.hxx>
#include <tools/solar.h>
@@ -728,7 +729,7 @@ bool OFlatTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 n
if(m_nMaxRowCount != 0 && m_nRowPos > m_nMaxRowCount)
return false;
++m_nRowPos;
- if(m_aRowPosToFilePos.size() > static_cast< vector< TRowPositionInFile >::size_type >(m_nRowPos))
+ if(m_aRowPosToFilePos.size() > o3tl::make_unsigned(m_nRowPos))
{
m_bNeedToReadLine = true;
m_nFilePos = m_aRowPosToFilePos[m_nRowPos].first;
@@ -768,7 +769,7 @@ bool OFlatTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 n
--m_nRowPos;
{
assert (m_nRowPos >= 0);
- assert(m_aRowPosToFilePos.size() >= static_cast< vector< TRowPositionInFile >::size_type >(m_nRowPos));
+ assert(m_aRowPosToFilePos.size() >= o3tl::make_unsigned(m_nRowPos));
const TRowPositionInFile &aPositions(m_aRowPosToFilePos[m_nRowPos]);
m_nFilePos = aPositions.first;
nCurPos = aPositions.second;
@@ -819,9 +820,9 @@ bool OFlatTable::seekRow(IResultSetHelper::Movement eCursorPosition, sal_Int32 n
}
assert(m_nRowPos >=0);
- assert(m_aRowPosToFilePos.size() > static_cast< vector< TRowPositionInFile >::size_type >(m_nRowPos));
+ assert(m_aRowPosToFilePos.size() > o3tl::make_unsigned(m_nRowPos));
assert(nOffset >= 0);
- if(m_aRowPosToFilePos.size() > static_cast< vector< TRowPositionInFile >::size_type >(nOffset))
+ if(m_aRowPosToFilePos.size() > o3tl::make_unsigned(nOffset))
{
m_nFilePos = m_aRowPosToFilePos[nOffset].first;
nCurPos = m_aRowPosToFilePos[nOffset].second;
diff --git a/connectivity/source/drivers/mork/MResultSet.cxx b/connectivity/source/drivers/mork/MResultSet.cxx
index 2275472c5a4a..d5cc06559e11 100644
--- a/connectivity/source/drivers/mork/MResultSet.cxx
+++ b/connectivity/source/drivers/mork/MResultSet.cxx
@@ -25,6 +25,7 @@
#include <connectivity/dbtools.hxx>
#include <comphelper/types.hxx>
#include <cppuhelper/typeprovider.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <vector>
@@ -1289,7 +1290,7 @@ bool OResultSet::validRow( sal_uInt32 nRow)
sal_Int32 nNumberOfRecords = m_aQueryHelper.getResultCount();
if (( nRow == 0 ) ||
- ( nRow > static_cast<sal_uInt32>(nNumberOfRecords)) ){
+ ( nRow > o3tl::make_unsigned(nNumberOfRecords)) ){
SAL_INFO("connectivity.mork", "validRow(" << nRow << "): return False");
return false;
}
diff --git a/connectivity/source/drivers/odbc/OResultSet.cxx b/connectivity/source/drivers/odbc/OResultSet.cxx
index e9345aeae6c9..e17032152433 100644
--- a/connectivity/source/drivers/odbc/OResultSet.cxx
+++ b/connectivity/source/drivers/odbc/OResultSet.cxx
@@ -33,6 +33,7 @@
#include <comphelper/types.hxx>
#include <connectivity/dbtools.hxx>
#include <connectivity/dbexception.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
using namespace ::comphelper;
@@ -815,7 +816,7 @@ void SAL_CALL OResultSet::insertRow( )
SQLLEN nRealLen = 0;
Sequence<sal_Int8> aBookmark(nMaxBookmarkLen);
- static_assert(static_cast<size_t>(nMaxBookmarkLen) >= sizeof(SQLLEN), "must be larger");
+ static_assert(o3tl::make_unsigned(nMaxBookmarkLen) >= sizeof(SQLLEN), "must be larger");
SQLRETURN nRet = N3SQLBindCol(m_aStatementHandle,
0,
diff --git a/connectivity/source/drivers/odbc/OTools.cxx b/connectivity/source/drivers/odbc/OTools.cxx
index fb0dc71d716f..4781415de474 100644
--- a/connectivity/source/drivers/odbc/OTools.cxx
+++ b/connectivity/source/drivers/odbc/OTools.cxx
@@ -20,6 +20,7 @@
#include <odbc/OTools.hxx>
#include <odbc/OFunctions.hxx>
#include <com/sun/star/sdbc/DataType.hpp>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <osl/endian.h>
#include <odbc/OConnection.hxx>
@@ -137,7 +138,7 @@ void OTools::getValue( OConnection const * _pConnection,
else
{
OSL_ENSURE(static_cast<size_t>(_nSize) == properSize, "connectivity::odbc::OTools::getValue got wrongly sized memory region to write result to");
- if ( static_cast<size_t>(_nSize) > properSize )
+ if ( o3tl::make_unsigned(_nSize) > properSize )
{
SAL_WARN( "connectivity.drivers", "memory region is too big - trying to fudge it");
memset(_pValue, 0, _nSize);
@@ -147,7 +148,7 @@ void OTools::getValue( OConnection const * _pConnection,
#endif
}
}
- OSL_ENSURE(static_cast<size_t>(_nSize) >= properSize, "memory region is too small");
+ OSL_ENSURE(o3tl::make_unsigned(_nSize) >= properSize, "memory region is too small");
SQLLEN pcbValue = SQL_NULL_DATA;
OTools::ThrowException(_pConnection,
(*reinterpret_cast<T3SQLGetData>(_pConnection->getOdbcFunction(ODBC3SQLFunctionId::GetData)))(_aStatementHandle,
diff --git a/cppuhelper/source/servicemanager.cxx b/cppuhelper/source/servicemanager.cxx
index 77e4d2d49e04..00b9c40213d5 100644
--- a/cppuhelper/source/servicemanager.cxx
+++ b/cppuhelper/source/servicemanager.cxx
@@ -34,6 +34,7 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/factory.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <osl/module.hxx>
#include <rtl/ref.hxx>
@@ -628,7 +629,7 @@ ImplementationWrapper::getSupportedServiceNames()
std::shared_ptr< cppuhelper::ServiceManager::Data::Implementation > impl = implementation_.lock();
assert(impl);
if (impl->services.size()
- > static_cast< sal_uInt32 >(SAL_MAX_INT32))
+ > o3tl::make_unsigned(SAL_MAX_INT32))
{
throw css::uno::RuntimeException(
("Implementation " + impl->name
@@ -935,7 +936,7 @@ cppuhelper::ServiceManager::getAvailableServiceNames()
if (isDisposed()) {
return css::uno::Sequence< OUString >();
}
- if (data_.services.size() > static_cast< sal_uInt32 >(SAL_MAX_INT32)) {
+ if (data_.services.size() > o3tl::make_unsigned(SAL_MAX_INT32)) {
throw css::uno::RuntimeException(
"getAvailableServiceNames: too many services",
static_cast< cppu::OWeakObject * >(this));
@@ -1426,7 +1427,7 @@ OUString cppuhelper::ServiceManager::readLegacyRdbString(
if (key.openKey(path, subkey) != RegError::NO_ERROR
|| subkey.getValueInfo(OUString(), &t, &s) != RegError::NO_ERROR
|| t != RegValueType::STRING
- || s == 0 || s > static_cast< sal_uInt32 >(SAL_MAX_INT32))
+ || s == 0 || s > o3tl::make_unsigned(SAL_MAX_INT32))
{
throw css::uno::DeploymentException(
"Failure reading legacy rdb file " + uri,
diff --git a/cui/source/options/optgenrl.cxx b/cui/source/options/optgenrl.cxx
index 71b61b0cca79..f8fdd3bec1fd 100644
--- a/cui/source/options/optgenrl.cxx
+++ b/cui/source/options/optgenrl.cxx
@@ -28,6 +28,7 @@
#include <i18nlangtag/languagetag.hxx>
#include <i18nlangtag/mslangid.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <unotools/saveopt.hxx>
#include <svl/intitem.hxx>
@@ -402,11 +403,11 @@ IMPL_LINK( SvxGeneralTabPage, ModifyHdl_Impl, weld::Entry&, rEdit, void )
{
OUString sShortName = rShortName.xEdit->get_text();
// clear short name if it contains more characters than the number of initials
- if (static_cast<unsigned>(sShortName.getLength()) > nInits)
+ if (o3tl::make_unsigned(sShortName.getLength()) > nInits)
{
rShortName.xEdit->set_text(OUString());
}
- while (static_cast<unsigned>(sShortName.getLength()) < nInits)
+ while (o3tl::make_unsigned(sShortName.getLength()) < nInits)
sShortName += " ";
OUString sName = rEdit.get_text();
OUString sLetter = sName.isEmpty()
diff --git a/cui/source/tabpages/numfmt.cxx b/cui/source/tabpages/numfmt.cxx
index 273386c5724b..db22b3cefbf9 100644
--- a/cui/source/tabpages/numfmt.cxx
+++ b/cui/source/tabpages/numfmt.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <svl/eitem.hxx>
#include <svl/intitem.hxx>
#include <sfx2/objsh.hxx>
@@ -1385,7 +1388,7 @@ bool SvxNumberFormatTabPage::Click_Impl(weld::Button& rIB)
m_xEdComment->set_text(m_xLbCategory->get_text(1));
- if( nFmtLbSelPos>=0 && static_cast<size_t>(nFmtLbSelPos)<aEntryList.size() )
+ if( nFmtLbSelPos>=0 && o3tl::make_unsigned(nFmtLbSelPos)<aEntryList.size() )
{
aFormat = aEntryList[nFmtLbSelPos];
}
diff --git a/dbaccess/source/core/api/RowSet.cxx b/dbaccess/source/core/api/RowSet.cxx
index 10432ffbfb7b..7e80d5e9ec22 100644
--- a/dbaccess/source/core/api/RowSet.cxx
+++ b/dbaccess/source/core/api/RowSet.cxx
@@ -71,6 +71,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
#include <i18nlangtag/languagetag.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/syslocale.hxx>
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
@@ -1455,7 +1456,7 @@ void SAL_CALL ORowSet::executeWithCompletion( const Reference< XInteractionHandl
Reference<XIndexAccess> xParamsAsIndicies = xParameters.is() ? xParameters->getParameters() : Reference<XIndexAccess>();
const sal_Int32 nParamCount = xParamsAsIndicies.is() ? xParamsAsIndicies->getCount() : 0;
- if ( m_aParametersSet.size() < static_cast<size_t>(nParamCount) )
+ if ( m_aParametersSet.size() < o3tl::make_unsigned(nParamCount) )
m_aParametersSet.resize( nParamCount ,false);
::dbtools::askForParameters( xComposer, this, m_xActiveConnection, _rxHandler,m_aParametersSet );
@@ -2438,7 +2439,7 @@ ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
if ( parameterIndex < 1 )
throwInvalidIndexException( *this );
- if ( m_aParametersSet.size() < static_cast<size_t>(parameterIndex) )
+ if ( m_aParametersSet.size() < o3tl::make_unsigned(parameterIndex) )
m_aParametersSet.resize( parameterIndex ,false);
m_aParametersSet[parameterIndex - 1] = true;
@@ -2450,13 +2451,13 @@ ORowSetValue& ORowSet::getParameterStorage(sal_Int32 parameterIndex)
impl_disposeParametersContainer_nothrow();
if ( m_pParameters.is() )
{
- if ( static_cast<size_t>(parameterIndex) > m_pParameters->size() )
+ if ( o3tl::make_unsigned(parameterIndex) > m_pParameters->size() )
throwInvalidIndexException( *this );
return (*m_pParameters)[ parameterIndex - 1 ];
}
}
- if ( m_aPrematureParamValues->get().size() < static_cast<size_t>(parameterIndex) )
+ if ( m_aPrematureParamValues->get().size() < o3tl::make_unsigned(parameterIndex) )
m_aPrematureParamValues->get().resize( parameterIndex );
return m_aPrematureParamValues->get()[ parameterIndex - 1 ];
}
diff --git a/dbaccess/source/core/api/RowSetBase.cxx b/dbaccess/source/core/api/RowSetBase.cxx
index c203056815cd..81ba20a3b7c1 100644
--- a/dbaccess/source/core/api/RowSetBase.cxx
+++ b/dbaccess/source/core/api/RowSetBase.cxx
@@ -35,6 +35,7 @@
#include <comphelper/sequence.hxx>
#include <comphelper/seqstream.hxx>
#include <connectivity/dbexception.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
using namespace dbaccess;
@@ -233,7 +234,7 @@ const ORowSetValue& ORowSetBase::impl_getValue(sal_Int32 columnIndex)
}
OSL_ENSURE(!m_aCurrentRow.isNull() && m_aCurrentRow < m_pCache->getEnd() && aCacheIter != m_pCache->m_aCacheIterators.end(),"Invalid iterator set for currentrow!");
ORowSetRow rRow = *m_aCurrentRow;
- OSL_ENSURE(rRow.is() && static_cast<sal_uInt16>(columnIndex) < (rRow->get()).size(),"Invalid size of vector!");
+ OSL_ENSURE(rRow.is() && o3tl::make_unsigned(columnIndex) < (rRow->get()).size(),"Invalid size of vector!");
#endif
return ((*m_aCurrentRow)->get())[m_nLastColumnIndex = columnIndex];
}
diff --git a/dbaccess/source/core/api/RowSetCache.cxx b/dbaccess/source/core/api/RowSetCache.cxx
index 1ca8ba61b7da..f5ca34c20667 100644
--- a/dbaccess/source/core/api/RowSetCache.cxx
+++ b/dbaccess/source/core/api/RowSetCache.cxx
@@ -52,6 +52,7 @@
#include <connectivity/sqlparse.hxx>
#include <sqlbison.hxx>
#include <tools/diagnose_ex.h>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <algorithm>
@@ -880,7 +881,7 @@ void ORowSetCache::moveWindow()
const sal_Int32 nOverlapSize = m_nEndPos - m_nStartPos;
const sal_Int32 nStartPosOffset = m_nStartPos - nNewStartPos; // by how much m_nStartPos moves
m_nStartPos = nNewStartPos;
- OSL_ENSURE( static_cast<ORowSetMatrix::size_type>(nOverlapSize) <= m_pMatrix->size(), "new window end is after end of cache matrix!" );
+ OSL_ENSURE( o3tl::make_unsigned(nOverlapSize) <= m_pMatrix->size(), "new window end is after end of cache matrix!" );
// the first position in m_pMatrix whose data we don't keep;
// content will be moved to m_pMatrix.begin()
ORowSetMatrix::iterator aEnd (m_pMatrix->begin() + nOverlapSize);
diff --git a/dbaccess/source/ui/browser/formadapter.cxx b/dbaccess/source/ui/browser/formadapter.cxx
index aea58079ff23..cd1f0e958f14 100644
--- a/dbaccess/source/ui/browser/formadapter.cxx
+++ b/dbaccess/source/ui/browser/formadapter.cxx
@@ -18,6 +18,7 @@
*/
#include <formadapter.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <comphelper/types.hxx>
#include <comphelper/enumhelper.hxx>
@@ -1491,14 +1492,14 @@ sal_Bool SAL_CALL SbaXFormAdapter::hasElements()
// css::container::XIndexContainer
void SAL_CALL SbaXFormAdapter::insertByIndex(sal_Int32 _rIndex, const Any& Element)
{
- if ( ( _rIndex < 0 ) || ( static_cast<size_t>(_rIndex) >= m_aChildren.size() ) )
+ if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
throw css::lang::IndexOutOfBoundsException();
implInsert(Element, _rIndex);
}
void SAL_CALL SbaXFormAdapter::removeByIndex(sal_Int32 _rIndex)
{
- if ( ( _rIndex < 0 ) || ( static_cast<size_t>(_rIndex) >= m_aChildren.size() ) )
+ if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
throw css::lang::IndexOutOfBoundsException();
Reference< css::form::XFormComponent > xAffected = *(m_aChildren.begin() + _rIndex);
@@ -1527,7 +1528,7 @@ void SAL_CALL SbaXFormAdapter::removeByIndex(sal_Int32 _rIndex)
// css::container::XIndexReplace
void SAL_CALL SbaXFormAdapter::replaceByIndex(sal_Int32 _rIndex, const Any& Element)
{
- if ( ( _rIndex < 0 ) || ( static_cast<size_t>(_rIndex) >= m_aChildren.size() ) )
+ if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
throw css::lang::IndexOutOfBoundsException();
// extract the form component
@@ -1594,7 +1595,7 @@ sal_Int32 SAL_CALL SbaXFormAdapter::getCount()
Any SAL_CALL SbaXFormAdapter::getByIndex(sal_Int32 _rIndex)
{
- if ( ( _rIndex < 0 ) || ( static_cast<size_t>(_rIndex) >= m_aChildren.size() ) )
+ if ( ( _rIndex < 0 ) || ( o3tl::make_unsigned(_rIndex) >= m_aChildren.size() ) )
throw css::lang::IndexOutOfBoundsException();
Reference< css::form::XFormComponent > xElement = *(m_aChildren.begin() + _rIndex);
diff --git a/dbaccess/source/ui/control/RelationControl.cxx b/dbaccess/source/ui/control/RelationControl.cxx
index 004096c45fa4..2f1421d85e7e 100644
--- a/dbaccess/source/ui/control/RelationControl.cxx
+++ b/dbaccess/source/ui/control/RelationControl.cxx
@@ -33,6 +33,7 @@
#include <UITools.hxx>
#include <RelControliFace.hxx>
#include <helpids.h>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <vector>
@@ -221,7 +222,7 @@ namespace dbaui
{
OUString sFieldName(m_pListCell->GetSelectedEntry());
OConnectionLineDataVec& rLines = m_pConnData->GetConnLineDataList();
- if ( rLines.size() <= static_cast<OConnectionLineDataVec::size_type>(nRow) )
+ if ( rLines.size() <= o3tl::make_unsigned(nRow) )
{
rLines.push_back(new OConnectionLineData());
nRow = rLines.size() - 1;
@@ -266,7 +267,7 @@ namespace dbaui
OUString ORelationControl::GetCellText( long nRow, sal_uInt16 nColId ) const
{
OUString sText;
- if ( m_pConnData->GetConnLineDataList().size() > static_cast<size_t>(nRow) )
+ if ( m_pConnData->GetConnLineDataList().size() > o3tl::make_unsigned(nRow) )
{
OConnectionLineDataRef pConnLineData = m_pConnData->GetConnLineDataList()[nRow];
switch( getColumnIdent( nColId ) )
diff --git a/dbaccess/source/ui/dlg/generalpage.cxx b/dbaccess/source/ui/dlg/generalpage.cxx
index cf564821fcf0..b94b63e9f24a 100644
--- a/dbaccess/source/ui/dlg/generalpage.cxx
+++ b/dbaccess/source/ui/dlg/generalpage.cxx
@@ -40,6 +40,7 @@
#include <UITools.hxx>
#include <comphelper/processfactory.hxx>
#include <unotools/confignode.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <dbwizsetup.hxx>
@@ -366,7 +367,7 @@ namespace dbaui
{
// get the type from the entry data
const sal_Int32 nSelected = _rBox.get_active();
- if (static_cast<size_t>(nSelected) >= m_aEmbeddedURLPrefixes.size() )
+ if (o3tl::make_unsigned(nSelected) >= m_aEmbeddedURLPrefixes.size() )
{
SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix");
return;
@@ -386,7 +387,7 @@ namespace dbaui
const sal_Int32 nSelected = _rBox.get_active();
if (nSelected == -1)
return;
- if (static_cast<size_t>(nSelected) >= m_aURLPrefixes.size() )
+ if (o3tl::make_unsigned(nSelected) >= m_aURLPrefixes.size() )
{
SAL_WARN("dbaccess.ui.generalpage", "Got out-of-range value '" << nSelected << "' from the DatasourceType selection ListBox's GetSelectedEntryPos(): no corresponding URL prefix");
return;
diff --git a/dbaccess/source/ui/dlg/paramdialog.cxx b/dbaccess/source/ui/dlg/paramdialog.cxx
index 982e28bba49e..dc7d01dfcbc8 100644
--- a/dbaccess/source/ui/dlg/paramdialog.cxx
+++ b/dbaccess/source/ui/dlg/paramdialog.cxx
@@ -30,6 +30,7 @@
#include <stringconstants.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tools/diagnose_ex.h>
#include <unotools/syslocale.hxx>
@@ -295,7 +296,7 @@ namespace dbaui
m_nCurrentlySelected = nSelected;
// with this the value isn't dirty
- OSL_ENSURE(static_cast<size_t>(m_nCurrentlySelected) < m_aVisitedParams.size(), "OParameterDialog::OnEntrySelected : invalid current entry !");
+ OSL_ENSURE(o3tl::make_unsigned(m_nCurrentlySelected) < m_aVisitedParams.size(), "OParameterDialog::OnEntrySelected : invalid current entry !");
m_aVisitedParams[m_nCurrentlySelected] &= ~VisitFlags::Dirty;
m_aResetVisitFlag.SetTimeout(1000);
@@ -309,7 +310,7 @@ namespace dbaui
OSL_ENSURE(m_nCurrentlySelected != -1, "OParameterDialog::OnVisitedTimeout : invalid call !");
// mark the currently selected entry as visited
- OSL_ENSURE(static_cast<size_t>(m_nCurrentlySelected) < m_aVisitedParams.size(), "OParameterDialog::OnVisitedTimeout : invalid entry !");
+ OSL_ENSURE(o3tl::make_unsigned(m_nCurrentlySelected) < m_aVisitedParams.size(), "OParameterDialog::OnVisitedTimeout : invalid entry !");
m_aVisitedParams[m_nCurrentlySelected] |= VisitFlags::Visited;
// was it the last "not visited yet" entry ?
@@ -334,7 +335,7 @@ namespace dbaui
IMPL_LINK(OParameterDialog, OnValueModified, weld::Entry&, rEdit, void)
{
// mark the currently selected entry as dirty
- OSL_ENSURE(static_cast<size_t>(m_nCurrentlySelected) < m_aVisitedParams.size(), "OParameterDialog::OnValueModified : invalid entry !");
+ OSL_ENSURE(o3tl::make_unsigned(m_nCurrentlySelected) < m_aVisitedParams.size(), "OParameterDialog::OnValueModified : invalid entry !");
m_aVisitedParams[m_nCurrentlySelected] |= VisitFlags::Dirty;
rEdit.set_message_type(weld::EntryMessageType::Normal);
}
diff --git a/dbaccess/source/ui/misc/WCopyTable.cxx b/dbaccess/source/ui/misc/WCopyTable.cxx
index 6be2d87fa9a9..ca85547679ce 100644
--- a/dbaccess/source/ui/misc/WCopyTable.cxx
+++ b/dbaccess/source/ui/misc/WCopyTable.cxx
@@ -52,7 +52,7 @@
#include <connectivity/dbtools.hxx>
#include <connectivity/dbmetadata.hxx>
#include <connectivity/dbexception.hxx>
-
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
#include <tools/debug.hxx>
@@ -1258,7 +1258,7 @@ Reference< XPropertySet > OCopyTableWizard::createTable()
if ( m_vColumnPositions.end() != aPosFind )
{
aPosFind->second = nNewPos;
- OSL_ENSURE( m_vColumnTypes.size() > size_t( aPosFind - m_vColumnPositions.begin() ),
+ OSL_ENSURE( m_vColumnTypes.size() > o3tl::make_unsigned( aPosFind - m_vColumnPositions.begin() ),
"Invalid index for vector!" );
m_vColumnTypes[ aPosFind - m_vColumnPositions.begin() ] = (*aFind)->second->GetType();
}
diff --git a/dbaccess/source/ui/querydesign/JAccess.cxx b/dbaccess/source/ui/querydesign/JAccess.cxx
index f2459ee67d32..703d91fe30f9 100644
--- a/dbaccess/source/ui/querydesign/JAccess.cxx
+++ b/dbaccess/source/ui/querydesign/JAccess.cxx
@@ -25,6 +25,7 @@
#include <JoinDesignView.hxx>
#include <JoinController.hxx>
#include <TableConnection.hxx>
+#include <o3tl/safeint.hxx>
namespace dbaui
{
@@ -71,7 +72,7 @@ namespace dbaui
OJoinTableView::OTableWindowMap::const_iterator aIter = std::next(m_pTableView->GetTabWinMap().begin(), i);
aRet = aIter->second->GetAccessible();
}
- else if( size_t(i - nTableWindowCount) < m_pTableView->getTableConnections().size() )
+ else if( o3tl::make_unsigned(i - nTableWindowCount) < m_pTableView->getTableConnections().size() )
aRet = m_pTableView->getTableConnections()[i - nTableWindowCount]->GetAccessible();
return aRet;
}
diff --git a/dbaccess/source/ui/querydesign/QueryDesignView.cxx b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
index 231d8fd6a701..da95ed304dae 100644
--- a/dbaccess/source/ui/querydesign/QueryDesignView.cxx
+++ b/dbaccess/source/ui/querydesign/QueryDesignView.cxx
@@ -26,6 +26,7 @@
#include <vcl/split.hxx>
#include <svl/undo.hxx>
#include <tools/diagnose_ex.h>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <adtabdlg.hxx>
#include <vcl/svapp.hxx>
@@ -2121,7 +2122,7 @@ namespace
sal_Int32 nFunctionType = FKT_NONE;
::connectivity::OSQLParseNode* pParamRef = nullptr;
sal_Int32 nColumnRefPos = pColumnRef->count() - 2;
- if ( nColumnRefPos >= 0 && static_cast<sal_uInt32>(nColumnRefPos) < pColumnRef->count() )
+ if ( nColumnRefPos >= 0 && o3tl::make_unsigned(nColumnRefPos) < pColumnRef->count() )
pParamRef = pColumnRef->getChild(nColumnRefPos);
if ( SQL_ISRULE(pColumnRef,general_set_fct)
diff --git a/drawinglayer/source/tools/emfpbrush.cxx b/drawinglayer/source/tools/emfpbrush.cxx
index 650f3e774d6e..892a22d5caa7 100644
--- a/drawinglayer/source/tools/emfpbrush.cxx
+++ b/drawinglayer/source/tools/emfpbrush.cxx
@@ -20,6 +20,7 @@
#include <basegfx/range/b2drange.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/polygon/b2dpolypolygontools.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include "emfpbrush.hxx"
#include "emfppath.hxx"
@@ -115,7 +116,7 @@ namespace emfplushelper
s.ReadInt32(surroundColorsNumber);
SAL_INFO("drawinglayer", "EMF+\t\t\t\t number of surround colors: " << surroundColorsNumber);
- if (surroundColorsNumber<0 || sal_uInt32(surroundColorsNumber)>SAL_MAX_INT32 / sizeof(::Color))
+ if (surroundColorsNumber<0 || o3tl::make_unsigned(surroundColorsNumber)>SAL_MAX_INT32 / sizeof(::Color))
{
surroundColorsNumber = SAL_MAX_INT32 / sizeof(::Color);
}
@@ -190,7 +191,7 @@ namespace emfplushelper
{
s.ReadInt32(blendPoints);
SAL_INFO("drawinglayer", "EMF+\t\t\t\tuse blend, points: " << blendPoints);
- if (blendPoints<0 || sal_uInt32(blendPoints)>SAL_MAX_INT32 / (2 * sizeof(float)))
+ if (blendPoints<0 || o3tl::make_unsigned(blendPoints)>SAL_MAX_INT32 / (2 * sizeof(float)))
blendPoints = SAL_MAX_INT32 / (2 * sizeof(float));
blendPositions.reset( new float[2 * blendPoints] );
blendFactors = blendPositions.get() + blendPoints;
@@ -213,12 +214,12 @@ namespace emfplushelper
s.ReadInt32(colorblendPoints);
SAL_INFO("drawinglayer", "EMF+\t\t\t\tUse color blend, points: " << colorblendPoints);
- if (colorblendPoints<0 || sal_uInt32(colorblendPoints)>SAL_MAX_INT32 / sizeof(float))
+ if (colorblendPoints<0 || o3tl::make_unsigned(colorblendPoints)>SAL_MAX_INT32 / sizeof(float))
{
colorblendPoints = SAL_MAX_INT32 / sizeof(float);
}
- if (sal_uInt32(colorblendPoints) > SAL_MAX_INT32 / sizeof(::Color))
+ if (o3tl::make_unsigned(colorblendPoints) > SAL_MAX_INT32 / sizeof(::Color))
{
colorblendPoints = SAL_MAX_INT32 / sizeof(::Color);
}
@@ -272,7 +273,7 @@ namespace emfplushelper
{
s.ReadInt32(blendPoints);
SAL_INFO("drawinglayer", "EMF+\t\t\t\tUse blend, points: " << blendPoints);
- if (blendPoints<0 || sal_uInt32(blendPoints)>SAL_MAX_INT32 / (2 * sizeof(float)))
+ if (blendPoints<0 || o3tl::make_unsigned(blendPoints)>SAL_MAX_INT32 / (2 * sizeof(float)))
blendPoints = SAL_MAX_INT32 / (2 * sizeof(float));
blendPositions.reset( new float[2 * blendPoints] );
blendFactors = blendPositions.get() + blendPoints;
@@ -295,12 +296,12 @@ namespace emfplushelper
s.ReadInt32(colorblendPoints);
SAL_INFO("drawinglayer", "EMF+\t\t\t\tUse color blend, points: " << colorblendPoints);
- if (colorblendPoints<0 || sal_uInt32(colorblendPoints)>SAL_MAX_INT32 / sizeof(float))
+ if (colorblendPoints<0 || o3tl::make_unsigned(colorblendPoints)>SAL_MAX_INT32 / sizeof(float))
{
colorblendPoints = SAL_MAX_INT32 / sizeof(float);
}
- if (sal_uInt32(colorblendPoints) > SAL_MAX_INT32 / sizeof(::Color))
+ if (o3tl::make_unsigned(colorblendPoints) > SAL_MAX_INT32 / sizeof(::Color))
{
colorblendPoints = sal_uInt32(SAL_MAX_INT32) / sizeof(::Color);
}
diff --git a/drawinglayer/source/tools/emfppath.cxx b/drawinglayer/source/tools/emfppath.cxx
index 5a40395e0f99..1f16c292cad8 100644
--- a/drawinglayer/source/tools/emfppath.cxx
+++ b/drawinglayer/source/tools/emfppath.cxx
@@ -20,6 +20,7 @@
#include <basegfx/point/b2dpoint.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolypolygon.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include "emfppath.hxx"
@@ -59,7 +60,7 @@ namespace emfplushelper
EMFPPath::EMFPPath (sal_Int32 _nPoints, bool bLines)
{
- if (_nPoints<0 || sal_uInt32(_nPoints)>SAL_MAX_INT32 / (2 * sizeof(float)))
+ if (_nPoints<0 || o3tl::make_unsigned(_nPoints)>SAL_MAX_INT32 / (2 * sizeof(float)))
{
_nPoints = SAL_MAX_INT32 / (2 * sizeof(float));
}
diff --git a/drawinglayer/source/tools/emfppen.cxx b/drawinglayer/source/tools/emfppen.cxx
index c09cd926a1d6..5182c84b023f 100644
--- a/drawinglayer/source/tools/emfppen.cxx
+++ b/drawinglayer/source/tools/emfppen.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/rendering/PathCapType.hpp>
#include <com/sun/star/rendering/PathJoinType.hpp>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include "emfppen.hxx"
@@ -305,7 +306,7 @@ namespace emfplushelper
s.ReadInt32(dashPatternLen);
SAL_INFO("drawinglayer", "EMF+\t\t\tdashPatternLen: " << dashPatternLen);
- if (dashPatternLen<0 || sal_uInt32(dashPatternLen)>SAL_MAX_INT32 / sizeof(float))
+ if (dashPatternLen<0 || o3tl::make_unsigned(dashPatternLen)>SAL_MAX_INT32 / sizeof(float))
{
dashPatternLen = SAL_MAX_INT32 / sizeof(float);
}
@@ -335,7 +336,7 @@ namespace emfplushelper
sal_Int32 compoundArrayLen;
s.ReadInt32(compoundArrayLen);
- if (compoundArrayLen<0 || sal_uInt32(compoundArrayLen)>SAL_MAX_INT32 / sizeof(float))
+ if (compoundArrayLen<0 || o3tl::make_unsigned(compoundArrayLen)>SAL_MAX_INT32 / sizeof(float))
{
compoundArrayLen = SAL_MAX_INT32 / sizeof(float);
}
diff --git a/editeng/source/accessibility/AccessibleParaManager.cxx b/editeng/source/accessibility/AccessibleParaManager.cxx
index 737e07468096..2fb3006da7b7 100644
--- a/editeng/source/accessibility/AccessibleParaManager.cxx
+++ b/editeng/source/accessibility/AccessibleParaManager.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/uno/Any.hxx>
#include <com/sun/star/uno/Reference.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <tools/debug.hxx>
#include <com/sun/star/accessibility/XAccessible.hpp>
@@ -62,7 +63,7 @@ namespace accessibility
void AccessibleParaManager::SetNum( sal_Int32 nNumParas )
{
- if( static_cast<size_t>(nNumParas) < maChildren.size() )
+ if( o3tl::make_unsigned(nNumParas) < maChildren.size() )
Release( nNumParas, maChildren.size() );
maChildren.resize( nNumParas );
@@ -95,10 +96,10 @@ namespace accessibility
void AccessibleParaManager::FireEvent( sal_Int32 nPara,
const sal_Int16 nEventId ) const
{
- DBG_ASSERT( 0 <= nPara && maChildren.size() > static_cast<size_t>(nPara),
+ DBG_ASSERT( 0 <= nPara && maChildren.size() > o3tl::make_unsigned(nPara),
"AccessibleParaManager::FireEvent: invalid index" );
- if( 0 <= nPara && maChildren.size() > static_cast<size_t>(nPara) )
+ if( 0 <= nPara && maChildren.size() > o3tl::make_unsigned(nPara) )
{
auto aChild( GetChild( nPara ).first.get() );
if( aChild.is() )
@@ -114,10 +115,10 @@ namespace accessibility
bool AccessibleParaManager::IsReferencable( sal_Int32 nChild ) const
{
- DBG_ASSERT( 0 <= nChild && maChildren.size() > static_cast<size_t>(nChild),
+ DBG_ASSERT( 0 <= nChild && maChildren.size() > o3tl::make_unsigned(nChild),
"AccessibleParaManager::IsReferencable: invalid index" );
- if( 0 <= nChild && maChildren.size() > static_cast<size_t>(nChild) )
+ if( 0 <= nChild && maChildren.size() > o3tl::make_unsigned(nChild) )
{
// retrieve hard reference from weak one
return IsReferencable( GetChild( nChild ).first.get() );
@@ -130,10 +131,10 @@ namespace accessibility
AccessibleParaManager::WeakChild AccessibleParaManager::GetChild( sal_Int32 nParagraphIndex ) const
{
- DBG_ASSERT( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex),
+ DBG_ASSERT( 0 <= nParagraphIndex && maChildren.size() > o3tl::make_unsigned(nParagraphIndex),
"AccessibleParaManager::GetChild: invalid index" );
- if( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex) )
+ if( 0 <= nParagraphIndex && maChildren.size() > o3tl::make_unsigned(nParagraphIndex) )
{
return maChildren[ nParagraphIndex ];
}
@@ -148,10 +149,10 @@ namespace accessibility
SvxEditSourceAdapter& rEditSource,
sal_Int32 nParagraphIndex )
{
- DBG_ASSERT( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex),
+ DBG_ASSERT( 0 <= nParagraphIndex && maChildren.size() > o3tl::make_unsigned(nParagraphIndex),
"AccessibleParaManager::CreateChild: invalid index" );
- if( 0 <= nParagraphIndex && maChildren.size() > static_cast<size_t>(nParagraphIndex) )
+ if( 0 <= nParagraphIndex && maChildren.size() > o3tl::make_unsigned(nParagraphIndex) )
{
// retrieve hard reference from weak one
auto aChild( GetChild( nParagraphIndex ).first.get() );
@@ -318,14 +319,14 @@ namespace accessibility
const uno::Any& rOldValue ) const
{
DBG_ASSERT( 0 <= nStartPara && 0 <= nEndPara &&
- maChildren.size() > static_cast<size_t>(nStartPara) &&
- maChildren.size() >= static_cast<size_t>(nEndPara) &&
+ maChildren.size() > o3tl::make_unsigned(nStartPara) &&
+ maChildren.size() >= o3tl::make_unsigned(nEndPara) &&
nEndPara >= nStartPara, "AccessibleParaManager::FireEvent: invalid index" );
if( 0 <= nStartPara && 0 <= nEndPara &&
- maChildren.size() > static_cast<size_t>(nStartPara) &&
- maChildren.size() >= static_cast<size_t>(nEndPara) &&
+ maChildren.size() > o3tl::make_unsigned(nStartPara) &&
+ maChildren.size() >= o3tl::make_unsigned(nEndPara) &&
nEndPara >= nStartPara )
{
VectorOfChildren::const_iterator front = maChildren.begin();
@@ -359,13 +360,13 @@ namespace accessibility
void AccessibleParaManager::Release( sal_Int32 nStartPara, sal_Int32 nEndPara )
{
DBG_ASSERT( 0 <= nStartPara && 0 <= nEndPara &&
- maChildren.size() > static_cast<size_t>(nStartPara) &&
- maChildren.size() >= static_cast<size_t>(nEndPara),
+ maChildren.size() > o3tl::make_unsigned(nStartPara) &&
+ maChildren.size() >= o3tl::make_unsigned(nEndPara),
"AccessibleParaManager::Release: invalid index" );
if( 0 <= nStartPara && 0 <= nEndPara &&
- maChildren.size() > static_cast<size_t>(nStartPara) &&
- maChildren.size() >= static_cast<size_t>(nEndPara) )
+ maChildren.size() > o3tl::make_unsigned(nStartPara) &&
+ maChildren.size() >= o3tl::make_unsigned(nEndPara) )
{
VectorOfChildren::iterator front = maChildren.begin();
VectorOfChildren::iterator back = front;
diff --git a/editeng/source/editeng/editobj.cxx b/editeng/source/editeng/editobj.cxx
index 80753a950c71..a0f46f0329ee 100644
--- a/editeng/source/editeng/editobj.cxx
+++ b/editeng/source/editeng/editobj.cxx
@@ -18,6 +18,8 @@
*/
#include <memory>
+
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <editeng/fieldupdater.hxx>
@@ -682,7 +684,7 @@ sal_Int32 EditTextObjectImpl::GetParagraphCount() const
OUString EditTextObjectImpl::GetText(sal_Int32 nPara) const
{
- if (nPara < 0 || static_cast<size_t>(nPara) >= aContents.size())
+ if (nPara < 0 || o3tl::make_unsigned(nPara) >= aContents.size())
return OUString();
return aContents[nPara]->GetText();
@@ -705,7 +707,7 @@ bool EditTextObjectImpl::HasOnlineSpellErrors() const
void EditTextObjectImpl::GetCharAttribs( sal_Int32 nPara, std::vector<EECharAttrib>& rLst ) const
{
- if (nPara < 0 || static_cast<size_t>(nPara) >= aContents.size())
+ if (nPara < 0 || o3tl::make_unsigned(nPara) >= aContents.size())
return;
rLst.clear();
@@ -747,7 +749,7 @@ const SvxFieldItem* EditTextObjectImpl::GetField() const
const SvxFieldData* EditTextObjectImpl::GetFieldData(sal_Int32 nPara, size_t nPos, sal_Int32 nType) const
{
- if (nPara < 0 || static_cast<size_t>(nPara) >= aContents.size())
+ if (nPara < 0 || o3tl::make_unsigned(nPara) >= aContents.size())
return nullptr;
const ContentInfo& rC = *aContents[nPara];
@@ -979,7 +981,7 @@ void EditTextObjectImpl::GetAllSections( std::vector<editeng::Section>& rAttrs )
void EditTextObjectImpl::GetStyleSheet(sal_Int32 nPara, OUString& rName, SfxStyleFamily& rFamily) const
{
- if (nPara < 0 || static_cast<size_t>(nPara) >= aContents.size())
+ if (nPara < 0 || o3tl::make_unsigned(nPara) >= aContents.size())
return;
const ContentInfo& rC = *aContents[nPara];
@@ -989,7 +991,7 @@ void EditTextObjectImpl::GetStyleSheet(sal_Int32 nPara, OUString& rName, SfxStyl
void EditTextObjectImpl::SetStyleSheet(sal_Int32 nPara, const OUString& rName, const SfxStyleFamily& rFamily)
{
- if (nPara < 0 || static_cast<size_t>(nPara) >= aContents.size())
+ if (nPara < 0 || o3tl::make_unsigned(nPara) >= aContents.size())
return;
ContentInfo& rC = *aContents[nPara];
diff --git a/editeng/source/editeng/edtspell.cxx b/editeng/source/editeng/edtspell.cxx
index e586a0d9d81f..db4fa899f34d 100644
--- a/editeng/source/editeng/edtspell.cxx
+++ b/editeng/source/editeng/edtspell.cxx
@@ -20,6 +20,7 @@
#include "impedit.hxx"
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <editeng/editview.hxx>
#include <editeng/editeng.hxx>
@@ -369,7 +370,7 @@ void WrongList::ClearWrongs( size_t nStart, size_t nEnd,
{
i->mnStart = nEnd;
// Blanks?
- while (i->mnStart < static_cast<size_t>(pNode->Len()) &&
+ while (i->mnStart < o3tl::make_unsigned(pNode->Len()) &&
(pNode->GetChar(i->mnStart) == ' ' ||
pNode->IsFeature(i->mnStart)))
{
diff --git a/editeng/source/editeng/impedit2.cxx b/editeng/source/editeng/impedit2.cxx
index 30e12bec9a56..805c043aa11f 100644
--- a/editeng/source/editeng/impedit2.cxx
+++ b/editeng/source/editeng/impedit2.cxx
@@ -50,6 +50,7 @@
#include <com/sun/star/system/XSystemShellExecute.hpp>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <sot/exchange.hxx>
#include <sot/formats.hxx>
@@ -2850,14 +2851,14 @@ EditPaM ImpEditEngine::ImpInsertParaBreak( EditPaM& rPaM, bool bKeepEndingAttrib
{
// Correct only if really a word gets overlapped in the process of
// Spell checking
- if (elem.mnStart > static_cast<size_t>(nEnd))
+ if (elem.mnStart > o3tl::make_unsigned(nEnd))
{
pRWrongs->push_back(elem);
editeng::MisspellRange& rRWrong = pRWrongs->back();
rRWrong.mnStart = rRWrong.mnStart - nEnd;
rRWrong.mnEnd = rRWrong.mnEnd - nEnd;
}
- else if (elem.mnStart < static_cast<size_t>(nEnd) && elem.mnEnd > static_cast<size_t>(nEnd))
+ else if (elem.mnStart < o3tl::make_unsigned(nEnd) && elem.mnEnd > o3tl::make_unsigned(nEnd))
elem.mnEnd = nEnd;
}
sal_Int32 nInv = nEnd ? nEnd-1 : nEnd;
diff --git a/editeng/source/editeng/impedit3.cxx b/editeng/source/editeng/impedit3.cxx
index 45205eaa2ab9..6ebd6fa49f48 100644
--- a/editeng/source/editeng/impedit3.cxx
+++ b/editeng/source/editeng/impedit3.cxx
@@ -65,6 +65,7 @@
#include <comphelper/processfactory.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <comphelper/string.hxx>
#include <comphelper/lok.hxx>
@@ -3410,7 +3411,7 @@ void ImpEditEngine::Paint( OutputDevice* pOutDev, tools::Rectangle aClipRect, Po
break;
}
- if(nStart < static_cast<size_t>(nIndex))
+ if(nStart < o3tl::make_unsigned(nIndex))
{
nStart = nIndex;
}
diff --git a/editeng/source/editeng/impedit4.cxx b/editeng/source/editeng/impedit4.cxx
index c690b35cd302..6d94c5ef8026 100644
--- a/editeng/source/editeng/impedit4.cxx
+++ b/editeng/source/editeng/impedit4.cxx
@@ -33,6 +33,7 @@
#include "editobj2.hxx"
#include <i18nlangtag/lang.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <editxml.hxx>
@@ -2234,7 +2235,7 @@ void ImpEditEngine::DoOnlineSpelling( ContentNode* pThisNodeOnly, bool bSpellAtC
EditSelection aSel( aPaM, aPaM );
while ( aSel.Max().GetNode() == pNode )
{
- if ( ( static_cast<size_t>(aSel.Min().GetIndex()) > nInvEnd )
+ if ( ( o3tl::make_unsigned(aSel.Min().GetIndex()) > nInvEnd )
|| ( ( aSel.Max().GetNode() == pLastNode ) && ( aSel.Max().GetIndex() >= pLastNode->Len() ) ) )
break; // Document end or end of invalid region
diff --git a/editeng/source/items/textitem.cxx b/editeng/source/items/textitem.cxx
index e7e3623f69eb..b24500387a61 100644
--- a/editeng/source/items/textitem.cxx
+++ b/editeng/source/items/textitem.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/frame/status/FontHeight.hpp>
#include <math.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <unotools/fontdefs.hxx>
#include <unotools/intlwrapper.hxx>
@@ -712,7 +713,7 @@ static sal_uInt32 lcl_GetRealHeight_Impl(sal_uInt32 nHeight, sal_uInt16 nProp, M
default:
break;
}
- nRet = (nDiff < 0 || nRet >= static_cast<unsigned short>(nDiff))
+ nRet = (nDiff < 0 || nRet >= o3tl::make_unsigned(nDiff))
? nRet - nDiff : 0;
//TODO: overflow in case nDiff < 0 and nRet - nDiff > SAL_MAX_UINT32
diff --git a/editeng/source/outliner/outliner.cxx b/editeng/source/outliner/outliner.cxx
index df08cebbc145..59a56189b2ab 100644
--- a/editeng/source/outliner/outliner.cxx
+++ b/editeng/source/outliner/outliner.cxx
@@ -47,6 +47,7 @@
#include <svl/itempool.hxx>
#include <libxml/xmlwriter.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <memory>
@@ -361,7 +362,7 @@ sal_Int32 Outliner::GetBulletsNumberingStatus() const
std::unique_ptr<OutlinerParaObject> Outliner::CreateParaObject( sal_Int32 nStartPara, sal_Int32 nCount ) const
{
if ( static_cast<sal_uLong>(nStartPara) + nCount >
- static_cast<sal_uLong>(pParaList->GetParagraphCount()) )
+ o3tl::make_unsigned(pParaList->GetParagraphCount()) )
nCount = pParaList->GetParagraphCount() - nStartPara;
// When a new OutlinerParaObject is created because a paragraph is just being deleted,
diff --git a/editeng/source/outliner/outlobj.cxx b/editeng/source/outliner/outlobj.cxx
index 8530c5dda55c..48c7aa02ab08 100644
--- a/editeng/source/outliner/outlobj.cxx
+++ b/editeng/source/outliner/outlobj.cxx
@@ -26,6 +26,7 @@
#include <osl/diagnose.h>
#include <o3tl/cow_wrapper.hxx>
+#include <o3tl/safeint.hxx>
#include <libxml/xmlwriter.h>
OutlinerParaObjData::OutlinerParaObjData( std::unique_ptr<EditTextObject> pEditTextObject, const ParagraphDataVector& rParagraphDataVector, bool bIsEditDoc ) :
@@ -169,7 +170,7 @@ sal_Int32 OutlinerParaObject::Count() const
sal_Int16 OutlinerParaObject::GetDepth(sal_Int32 nPara) const
{
- if(0 <= nPara && static_cast<size_t>(nPara) < mpImpl->maParagraphDataVector.size())
+ if(0 <= nPara && o3tl::make_unsigned(nPara) < mpImpl->maParagraphDataVector.size())
{
return mpImpl->maParagraphDataVector[nPara].getDepth();
}
@@ -186,7 +187,7 @@ const EditTextObject& OutlinerParaObject::GetTextObject() const
const ParagraphData& OutlinerParaObject::GetParagraphData(sal_Int32 nIndex) const
{
- if(0 <= nIndex && static_cast<size_t>(nIndex) < mpImpl->maParagraphDataVector.size())
+ if(0 <= nIndex && o3tl::make_unsigned(nIndex) < mpImpl->maParagraphDataVector.size())
{
return mpImpl->maParagraphDataVector[nIndex];
}
diff --git a/editeng/source/outliner/paralist.cxx b/editeng/source/outliner/paralist.cxx
index 9bf4e555ea1f..4e03e24c2438 100644
--- a/editeng/source/outliner/paralist.cxx
+++ b/editeng/source/outliner/paralist.cxx
@@ -22,7 +22,7 @@
#include <editeng/outliner.hxx>
#include <editeng/numdef.hxx>
-
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <tools/debug.hxx>
@@ -103,11 +103,11 @@ void ParagraphList::Append( std::unique_ptr<Paragraph> pPara)
void ParagraphList::Insert( std::unique_ptr<Paragraph> pPara, sal_Int32 nAbsPos)
{
- SAL_WARN_IF( nAbsPos < 0 || (maEntries.size() < static_cast<size_t>(nAbsPos) && nAbsPos != EE_PARA_APPEND),
+ SAL_WARN_IF( nAbsPos < 0 || (maEntries.size() < o3tl::make_unsigned(nAbsPos) && nAbsPos != EE_PARA_APPEND),
"editeng", "ParagraphList::Insert - bad insert position " << nAbsPos);
SAL_WARN_IF( maEntries.size() >= EE_PARA_MAX_COUNT, "editeng", "ParagraphList::Insert - overflow");
- if (nAbsPos < 0 || maEntries.size() <= static_cast<size_t>(nAbsPos))
+ if (nAbsPos < 0 || maEntries.size() <= o3tl::make_unsigned(nAbsPos))
Append( std::move(pPara) );
else
maEntries.insert(maEntries.begin()+nAbsPos, std::move(pPara));
@@ -115,7 +115,7 @@ void ParagraphList::Insert( std::unique_ptr<Paragraph> pPara, sal_Int32 nAbsPos)
void ParagraphList::Remove( sal_Int32 nPara )
{
- if (nPara < 0 || maEntries.size() <= static_cast<size_t>(nPara))
+ if (nPara < 0 || maEntries.size() <= o3tl::make_unsigned(nPara))
{
SAL_WARN( "editeng", "ParagraphList::Remove - out of bounds " << nPara);
return;
@@ -126,7 +126,7 @@ void ParagraphList::Remove( sal_Int32 nPara )
void ParagraphList::MoveParagraphs( sal_Int32 nStart, sal_Int32 nDest, sal_Int32 _nCount )
{
- OSL_ASSERT(static_cast<size_t>(nStart) < maEntries.size() && static_cast<size_t>(nDest) < maEntries.size());
+ OSL_ASSERT(o3tl::make_unsigned(nStart) < maEntries.size() && o3tl::make_unsigned(nDest) < maEntries.size());
if ( (( nDest < nStart ) || ( nDest >= ( nStart + _nCount ) )) && nStart >= 0 && nDest >= 0 && _nCount >= 0 )
{
diff --git a/editeng/source/outliner/paralist.hxx b/editeng/source/outliner/paralist.hxx
index 7b78dfcd82b4..0b60ac78eb9c 100644
--- a/editeng/source/outliner/paralist.hxx
+++ b/editeng/source/outliner/paralist.hxx
@@ -27,6 +27,7 @@
#include <vector>
#include <editeng/outliner.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/link.hxx>
class Paragraph;
@@ -50,7 +51,7 @@ public:
Paragraph* GetParagraph( sal_Int32 nPos ) const
{
- return 0 <= nPos && static_cast<size_t>(nPos) < maEntries.size() ? maEntries[nPos].get() : nullptr;
+ return 0 <= nPos && o3tl::make_unsigned(nPos) < maEntries.size() ? maEntries[nPos].get() : nullptr;
}
sal_Int32 GetAbsPos( Paragraph const * pParent ) const;
diff --git a/editeng/source/uno/unotext2.cxx b/editeng/source/uno/unotext2.cxx
index 72980c959a9c..4e1591e60acf 100644
--- a/editeng/source/uno/unotext2.cxx
+++ b/editeng/source/uno/unotext2.cxx
@@ -21,6 +21,7 @@
#include <initializer_list>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <rtl/instance.hxx>
@@ -94,7 +95,7 @@ sal_Bool SAL_CALL SvxUnoTextContentEnumeration::hasMoreElements()
{
SolarMutexGuard aGuard;
if( mpEditSource && !maContents.empty() )
- return static_cast<unsigned>(mnNextParagraph) < maContents.size();
+ return o3tl::make_unsigned(mnNextParagraph) < maContents.size();
else
return false;
}
diff --git a/emfio/source/reader/mtftools.cxx b/emfio/source/reader/mtftools.cxx
index 461109067f66..15ede2bf6d40 100644
--- a/emfio/source/reader/mtftools.cxx
+++ b/emfio/source/reader/mtftools.cxx
@@ -621,7 +621,7 @@ namespace emfio
GDIObj *pGDIObj = nullptr;
- if ( static_cast<sal_uInt32>(nIndex) < mvGDIObj.size() )
+ if ( o3tl::make_unsigned(nIndex) < mvGDIObj.size() )
pGDIObj = mvGDIObj[ nIndex ].get();
if ( pGDIObj )
@@ -764,7 +764,7 @@ namespace emfio
}
}
}
- if ( static_cast<sal_uInt32>(nIndex) >= mvGDIObj.size() )
+ if ( o3tl::make_unsigned(nIndex) >= mvGDIObj.size() )
ImplResizeObjectArry( nIndex + 16 );
mvGDIObj[ nIndex ] = std::move(pObject);
@@ -780,7 +780,7 @@ namespace emfio
{
if ( ( nIndex & ENHMETA_STOCK_OBJECT ) == 0 )
{
- if ( static_cast<sal_uInt32>(nIndex) < mvGDIObj.size() )
+ if ( o3tl::make_unsigned(nIndex) < mvGDIObj.size() )
{
mvGDIObj[ nIndex ].reset();
}
diff --git a/emfio/source/reader/wmfreader.cxx b/emfio/source/reader/wmfreader.cxx
index a070d8cfbea3..7249b61017ff 100644
--- a/emfio/source/reader/wmfreader.cxx
+++ b/emfio/source/reader/wmfreader.cxx
@@ -22,6 +22,7 @@
#include <memory>
#include <o3tl/optional.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/crc.h>
#include <rtl/tencinfo.h>
#include <sal/log.hxx>
@@ -590,7 +591,7 @@ namespace emfio
auto nMaxStreamPos = nRecordPos + nRecSize;
auto nRemainingSize = std::min(mpInputStream->remainingSize(), nMaxStreamPos - mpInputStream->Tell());
- if (nRemainingSize < static_cast<sal_uInt32>(nOriginalBlockLen))
+ if (nRemainingSize < o3tl::make_unsigned(nOriginalBlockLen))
{
SAL_WARN("vcl.wmf", "exttextout record claimed more data than the stream can provide");
nOriginalTextLen = nOriginalBlockLen = nRemainingSize;
diff --git a/extensions/source/dbpilots/groupboxwiz.cxx b/extensions/source/dbpilots/groupboxwiz.cxx
index 97bf0273da38..4e723e1685e3 100644
--- a/extensions/source/dbpilots/groupboxwiz.cxx
+++ b/extensions/source/dbpilots/groupboxwiz.cxx
@@ -24,6 +24,7 @@
#include "optiongrouplayouter.hxx"
#include <helpids.h>
#include <comphelper/processfactory.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#define GBW_STATE_OPTIONLIST 0
@@ -361,12 +362,12 @@ namespace dbp
if (::vcl::WizardTypes::WizardState(-1) != m_nLastSelection)
{
// save the value for the last option
- DBG_ASSERT(static_cast<size_t>(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
+ DBG_ASSERT(o3tl::make_unsigned(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid previous selection index!");
m_aUncommittedValues[m_nLastSelection] = m_xValue->get_text();
}
m_nLastSelection = m_xOptions->get_selected_index();
- DBG_ASSERT(static_cast<size_t>(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
+ DBG_ASSERT(o3tl::make_unsigned(m_nLastSelection) < m_aUncommittedValues.size(), "OOptionValuesPage::implTraveledOptions: invalid new selection index!");
m_xValue->set_text(m_aUncommittedValues[m_nLastSelection]);
}
diff --git a/extensions/source/scanner/sane.cxx b/extensions/source/scanner/sane.cxx
index 67889ce00416..c58cf1e15c7c 100644
--- a/extensions/source/scanner/sane.cxx
+++ b/extensions/source/scanner/sane.cxx
@@ -20,6 +20,8 @@
#include <cstdarg>
#include <type_traits>
#include <math.h>
+
+#include <o3tl/safeint.hxx>
#include <osl/file.h>
#include <sal/log.hxx>
#include <tools/stream.hxx>
@@ -270,7 +272,7 @@ void Sane::ReloadOptions()
fprintf( stderr, "Error: sane driver returned %s while reading number of options !\n", p_strstatus( nStatus ) );
mnOptions = pOptions[ 0 ];
- if( static_cast<size_t>(pZero->size) > sizeof( SANE_Word ) )
+ if( o3tl::make_unsigned(pZero->size) > sizeof( SANE_Word ) )
fprintf( stderr, "driver returned number of options with larger size than SANE_Word!!!\n" );
mppOptions.reset(new const SANE_Option_Descriptor*[ mnOptions ]);
mppOptions[ 0 ] = pZero;
diff --git a/extensions/source/scanner/scanunx.cxx b/extensions/source/scanner/scanunx.cxx
index bd261d694c85..41c0b66dba24 100644
--- a/extensions/source/scanner/scanunx.cxx
+++ b/extensions/source/scanner/scanunx.cxx
@@ -19,6 +19,7 @@
#include "scanner.hxx"
#include "sanedlg.hxx"
+#include <o3tl/safeint.hxx>
#include <osl/thread.hxx>
#include <sal/log.hxx>
#include <tools/solar.h>
@@ -245,7 +246,7 @@ sal_Bool ScannerManager::configureScannerAndScan( ScannerContext& scanner_contex
SAL_INFO("extensions.scanner", "ScannerManager::configureScanner");
- if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() )
+ if( scanner_context.InternalData < 0 || o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
throw ScannerException(
"Scanner does not exist",
Reference< XScannerManager >( this ),
@@ -281,7 +282,7 @@ void ScannerManager::startScan( const ScannerContext& scanner_context,
SAL_INFO("extensions.scanner", "ScannerManager::startScan");
- if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() )
+ if( scanner_context.InternalData < 0 || o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
throw ScannerException(
"Scanner does not exist",
Reference< XScannerManager >( this ),
@@ -306,7 +307,7 @@ ScanError ScannerManager::getError( const ScannerContext& scanner_context )
osl::MutexGuard aGuard( theSaneProtector::get() );
sanevec &rSanes = theSanes::get().m_aSanes;
- if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() )
+ if( scanner_context.InternalData < 0 || o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
throw ScannerException(
"Scanner does not exist",
Reference< XScannerManager >( this ),
@@ -324,7 +325,7 @@ Reference< css::awt::XBitmap > ScannerManager::getBitmap( const ScannerContext&
osl::MutexGuard aGuard( theSaneProtector::get() );
sanevec &rSanes = theSanes::get().m_aSanes;
- if( scanner_context.InternalData < 0 || static_cast<sal_uLong>(scanner_context.InternalData) >= rSanes.size() )
+ if( scanner_context.InternalData < 0 || o3tl::make_unsigned(scanner_context.InternalData) >= rSanes.size() )
throw ScannerException(
"Scanner does not exist",
Reference< XScannerManager >( this ),
diff --git a/filter/source/graphicfilter/icgm/cgm.cxx b/filter/source/graphicfilter/icgm/cgm.cxx
index 09abcac8d136..9a13e5ebb99e 100644
--- a/filter/source/graphicfilter/icgm/cgm.cxx
+++ b/filter/source/graphicfilter/icgm/cgm.cxx
@@ -18,7 +18,7 @@
*/
#include <com/sun/star/task/XStatusIndicator.hpp>
-
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <tools/stream.hxx>
#include "bitmap.hxx"
@@ -95,7 +95,7 @@ sal_uInt8 CGM::ImplGetByte( sal_uInt32 nSource, sal_uInt32 nPrecision )
sal_Int32 CGM::ImplGetI( sal_uInt32 nPrecision )
{
sal_uInt8* pSource = mpSource + mnParaSize;
- if (pSource > mpEndValidSource || static_cast<sal_uIntPtr>(mpEndValidSource - pSource) < nPrecision)
+ if (pSource > mpEndValidSource || o3tl::make_unsigned(mpEndValidSource - pSource) < nPrecision)
throw css::uno::Exception("attempt to read past end of input", nullptr);
mnParaSize += nPrecision;
switch( nPrecision )
@@ -127,7 +127,7 @@ sal_Int32 CGM::ImplGetI( sal_uInt32 nPrecision )
sal_uInt32 CGM::ImplGetUI( sal_uInt32 nPrecision )
{
sal_uInt8* pSource = mpSource + mnParaSize;
- if (pSource > mpEndValidSource || static_cast<sal_uIntPtr>(mpEndValidSource - pSource) < nPrecision)
+ if (pSource > mpEndValidSource || o3tl::make_unsigned(mpEndValidSource - pSource) < nPrecision)
throw css::uno::Exception("attempt to read past end of input", nullptr);
mnParaSize += nPrecision;
switch( nPrecision )
@@ -182,7 +182,7 @@ double CGM::ImplGetFloat( RealPrecision eRealPrecision, sal_uInt32 nRealSize )
const bool bCompatible = false;
#endif
- if (static_cast<sal_uIntPtr>(mpEndValidSource - (mpSource + mnParaSize)) < nRealSize)
+ if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nRealSize)
throw css::uno::Exception("attempt to read past end of input", nullptr);
if ( bCompatible )
diff --git a/filter/source/graphicfilter/icgm/class1.cxx b/filter/source/graphicfilter/icgm/class1.cxx
index 30e28dd820cc..ec8cd9246cdb 100644
--- a/filter/source/graphicfilter/icgm/class1.cxx
+++ b/filter/source/graphicfilter/icgm/class1.cxx
@@ -188,7 +188,7 @@ void CGM::ImplDoClass1()
ImplGetUI16(); // skip CharSetType
sal_uInt32 nSize = ImplGetUI(1);
- if (static_cast<sal_uIntPtr>(mpEndValidSource - (mpSource + mnParaSize)) < nSize)
+ if (o3tl::make_unsigned(mpEndValidSource - (mpSource + mnParaSize)) < nSize)
throw css::uno::Exception("attempt to read past end of input", nullptr);
pElement->aFontList.InsertCharSet( mpSource + mnParaSize, nSize );
diff --git a/filter/source/graphicfilter/icgm/class7.cxx b/filter/source/graphicfilter/icgm/class7.cxx
index 5de4680e08f6..1b51ce98e71c 100644
--- a/filter/source/graphicfilter/icgm/class7.cxx
+++ b/filter/source/graphicfilter/icgm/class7.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include "cgm.hxx"
#include "chart.hxx"
@@ -75,7 +78,7 @@ void CGM::ImplDoClass7()
case 0x262 : /*AppData - ENDGROUP */break;
case 0x264 : /*AppData - DATANODE*/
{
- if (static_cast<size_t>(mpEndValidSource - pAppData) < sizeof(DataNode))
+ if (o3tl::make_unsigned(mpEndValidSource - pAppData) < sizeof(DataNode))
throw css::uno::Exception("attempt to read past end of input", nullptr);
mpChart->mDataNode[ 0 ] = *reinterpret_cast<DataNode*>( pAppData );
diff --git a/filter/source/graphicfilter/idxf/dxfentrd.cxx b/filter/source/graphicfilter/idxf/dxfentrd.cxx
index dfc14ba0edcb..883dcc991818 100644
--- a/filter/source/graphicfilter/idxf/dxfentrd.cxx
+++ b/filter/source/graphicfilter/idxf/dxfentrd.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include "dxfentrd.hxx"
@@ -417,7 +420,7 @@ void DXFLWPolyLineEntity::EvaluateGroup( DXFGroupReader & rDGR )
{
nCount = rDGR.GetI();
// limit alloc to max reasonable size based on remaining data in stream
- if (nCount > 0 && static_cast<sal_uInt32>(nCount) <= rDGR.remainingSize())
+ if (nCount > 0 && o3tl::make_unsigned(nCount) <= rDGR.remainingSize())
aP.reserve(nCount);
else
nCount = 0;
@@ -584,7 +587,7 @@ bool DXFBoundaryPathData::EvaluateGroup( DXFGroupReader & rDGR )
{
nPointCount = rDGR.GetI();
// limit alloc to max reasonable size based on remaining data in stream
- if (nPointCount > 0 && static_cast<sal_uInt32>(nPointCount) <= rDGR.remainingSize())
+ if (nPointCount > 0 && o3tl::make_unsigned(nPointCount) <= rDGR.remainingSize())
aP.reserve(nPointCount);
else
nPointCount = 0;
@@ -672,7 +675,7 @@ void DXFHatchEntity::EvaluateGroup( DXFGroupReader & rDGR )
bIsInBoundaryPathContext = true;
nBoundaryPathCount = rDGR.GetI();
// limit alloc to max reasonable size based on remaining data in stream
- if (nBoundaryPathCount > 0 && static_cast<sal_uInt32>(nBoundaryPathCount) <= rDGR.remainingSize())
+ if (nBoundaryPathCount > 0 && o3tl::make_unsigned(nBoundaryPathCount) <= rDGR.remainingSize())
pBoundaryPathData.reset( new DXFBoundaryPathData[ nBoundaryPathCount ] );
else
nBoundaryPathCount = 0;
diff --git a/filter/source/graphicfilter/ieps/ieps.cxx b/filter/source/graphicfilter/ieps/ieps.cxx
index 7cf34b6493aa..1aaed97295b6 100644
--- a/filter/source/graphicfilter/ieps/ieps.cxx
+++ b/filter/source/graphicfilter/ieps/ieps.cxx
@@ -493,7 +493,7 @@ static void MakePreview(sal_uInt8* pBuf, sal_uInt32 nBytesRead,
--nRemainingBytes;
}
nLen = ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
- if (static_cast<sal_uInt32>(nLen) < nRemainingBytes)
+ if (o3tl::make_unsigned(nLen) < nRemainingBytes)
{
sal_uInt8 aOldValue(pDest[ nLen ]); pDest[ nLen ] = 0;
if ( strcmp( reinterpret_cast<char*>(pDest), "none" ) != 0 )
@@ -516,7 +516,7 @@ static void MakePreview(sal_uInt8* pBuf, sal_uInt32 nBytesRead,
--nRemainingBytes;
}
nLen = ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
- if (static_cast<sal_uInt32>(nLen) < nRemainingBytes)
+ if (o3tl::make_unsigned(nLen) < nRemainingBytes)
{
sal_uInt8 aOldValue(pDest[nLen]); pDest[nLen] = 0;
const char* pStr = reinterpret_cast<char*>(pDest);
@@ -536,7 +536,7 @@ static void MakePreview(sal_uInt8* pBuf, sal_uInt32 nBytesRead,
--nRemainingBytes;
}
nLen = ImplGetLen(pDest, std::min<sal_uInt32>(nRemainingBytes, 32));
- if (static_cast<sal_uInt32>(nLen) < nRemainingBytes)
+ if (o3tl::make_unsigned(nLen) < nRemainingBytes)
{
sal_uInt8 aOldValue(pDest[ nLen ]); pDest[ nLen ] = 0;
if ( strcmp( reinterpret_cast<char*>(pDest), "none" ) != 0 )
diff --git a/filter/source/msfilter/msdffimp.cxx b/filter/source/msfilter/msdffimp.cxx
index 753b3b11a69e..800a675dc54b 100644
--- a/filter/source/msfilter/msdffimp.cxx
+++ b/filter/source/msfilter/msdffimp.cxx
@@ -25,6 +25,7 @@
#include <vector>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <tools/solar.h>
#include <sal/log.hxx>
@@ -719,7 +720,7 @@ void SvxMSDffManager::SolveSolver( const SvxMSDffSolverContainer& rSolver )
{
css::uno::Sequence< css::drawing::EnhancedCustomShapeParameterPair > aCoordinates;
*pAny >>= aCoordinates;
- if ( nPt < static_cast<sal_uInt32>(aCoordinates.getLength()) )
+ if ( nPt < o3tl::make_unsigned(aCoordinates.getLength()) )
{
nId = 4;
css::drawing::EnhancedCustomShapeParameterPair& rPara = aCoordinates[ nPt ];
@@ -4217,7 +4218,7 @@ SdrObject* SvxMSDffManager::ImportGroup( const DffRecordHeader& rHd, SvStream& r
}
}
}
- if (size_t(nCalledByGroup) < maPendingGroupData.size())
+ if (o3tl::make_unsigned(nCalledByGroup) < maPendingGroupData.size())
{
// finalization for this group is pending, do it now
pRet = FinalizeObj(maPendingGroupData.back().first, pRet);
@@ -4961,7 +4962,7 @@ SdrObject* SvxMSDffManager::ImportShape( const DffRecordHeader& rHd, SvStream& r
// If this shape opens a new group, push back its object data because
// finalization will be called when nested objects have been imported;
// otherwise, just finalize here
- if (size_t(nCalledByGroup) > maPendingGroupData.size())
+ if (o3tl::make_unsigned(nCalledByGroup) > maPendingGroupData.size())
{
auto xHdClone = std::make_shared<DffRecordHeader>(aObjData.rSpHd);
maPendingGroupData.emplace_back(DffObjData(xHdClone, aObjData), xHdClone );
diff --git a/filter/source/msfilter/mstoolbar.cxx b/filter/source/msfilter/mstoolbar.cxx
index 7f0e7d70b9f6..f44cd2bbb3ca 100644
--- a/filter/source/msfilter/mstoolbar.cxx
+++ b/filter/source/msfilter/mstoolbar.cxx
@@ -7,6 +7,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
#include <filter/msfilter/mstoolbar.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/container/XIndexContainer.hpp>
@@ -676,7 +677,7 @@ bool TBCCDData::Read( SvStream &rS)
if (cwstrItems > 0)
{
//each WString is at least one byte
- if (rS.remainingSize() < static_cast<size_t>(cwstrItems))
+ if (rS.remainingSize() < o3tl::make_unsigned(cwstrItems))
return false;
for( sal_Int32 index=0; index < cwstrItems; ++index )
{
diff --git a/filter/source/msfilter/svdfppt.cxx b/filter/source/msfilter/svdfppt.cxx
index 83856b5d5499..1cae88f4870f 100644
--- a/filter/source/msfilter/svdfppt.cxx
+++ b/filter/source/msfilter/svdfppt.cxx
@@ -1217,7 +1217,7 @@ SdrObject* SdrEscherImport::ProcessObj( SvStream& rSt, DffObjData& rObjData, Svx
rSt.ReadInt16( nRowCount ).ReadInt16( i ).ReadInt16( i );
const size_t nMinRecordSize = 4;
const size_t nMaxRecords = rSt.remainingSize() / nMinRecordSize;
- if (nRowCount > 0 && static_cast<size_t>(nRowCount) > nMaxRecords)
+ if (nRowCount > 0 && o3tl::make_unsigned(nRowCount) > nMaxRecords)
{
SAL_WARN("filter.ms", "Parsing error: " << nMaxRecords <<
" max possible entries, but " << nRowCount << " claimed, truncating");
@@ -5366,7 +5366,7 @@ void PPTStyleTextPropReader::Init( SvStream& rIn, const DffRecordHeader& rTextHe
}
else
{
- if (nCharReadCnt > static_cast<sal_uInt32>(aString.getLength()))
+ if (nCharReadCnt > o3tl::make_unsigned(aString.getLength()))
aCharPropSet.maString = OUString();
else
{
diff --git a/forms/source/component/Filter.cxx b/forms/source/component/Filter.cxx
index 8bc457ec3e93..af002b13ed58 100644
--- a/forms/source/component/Filter.cxx
+++ b/forms/source/component/Filter.cxx
@@ -59,6 +59,7 @@
#include <connectivity/dbtools.hxx>
#include <connectivity/formattedcolumnvalue.hxx>
#include <connectivity/predicateinput.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/diagnose_ex.h>
#include <unotools/localedatawrapper.hxx>
@@ -458,7 +459,7 @@ namespace frm
::std::vector< OUString > aProposals;
aProposals.reserve(16);
- while ( xListCursor->next() && ( aProposals.size() < size_t( SHRT_MAX ) ) )
+ while ( xListCursor->next() && ( aProposals.size() < o3tl::make_unsigned( SHRT_MAX ) ) )
{
const OUString sCurrentValue = aFormatter.getFormattedValue();
aProposals.push_back( sCurrentValue );
diff --git a/forms/source/component/GroupManager.cxx b/forms/source/component/GroupManager.cxx
index 7131dab79753..56a16e57359d 100644
--- a/forms/source/component/GroupManager.cxx
+++ b/forms/source/component/GroupManager.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/form/FormComponentType.hpp>
#include <comphelper/property.hxx>
#include <comphelper/types.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tools/solar.h>
@@ -322,7 +323,7 @@ sal_Int32 OGroupManager::getGroupCount() const
void OGroupManager::getGroup(sal_Int32 nGroup, Sequence< Reference<XControlModel> >& _rGroup, OUString& _rName)
{
- OSL_ENSURE(nGroup >= 0 && static_cast<size_t>(nGroup) < m_aActiveGroupMap.size(),"OGroupManager::getGroup: Invalid group index!");
+ OSL_ENSURE(nGroup >= 0 && o3tl::make_unsigned(nGroup) < m_aActiveGroupMap.size(),"OGroupManager::getGroup: Invalid group index!");
OGroupArr::iterator aGroupPos = m_aActiveGroupMap[nGroup];
_rName = aGroupPos->second.GetGroupName();
_rGroup = aGroupPos->second.GetControlModels();
diff --git a/forms/source/component/ListBox.cxx b/forms/source/component/ListBox.cxx
index e98c7883f3c9..a578ac489e50 100644
--- a/forms/source/component/ListBox.cxx
+++ b/forms/source/component/ListBox.cxx
@@ -49,6 +49,7 @@
#include <connectivity/dbconversion.hxx>
#include <cppuhelper/queryinterface.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <tools/diagnose_ex.h>
#include <sal/log.hxx>
@@ -1537,8 +1538,8 @@ namespace frm
Any operator ()( sal_Int16 _nIndex )
{
- OSL_ENSURE( static_cast<ValueList::size_type>(_nIndex) < m_rList.size(), "ExtractAnyFromValueList: inconsistence!" );
- if ( static_cast<ValueList::size_type>(_nIndex) < m_rList.size() )
+ OSL_ENSURE( o3tl::make_unsigned(_nIndex) < m_rList.size(), "ExtractAnyFromValueList: inconsistence!" );
+ if ( o3tl::make_unsigned(_nIndex) < m_rList.size() )
return m_rList[ _nIndex ].makeAny();
return Any();
}
diff --git a/fpicker/source/office/fileview.cxx b/fpicker/source/office/fileview.cxx
index 1021db94e86f..b90d6ca9bb7a 100644
--- a/fpicker/source/office/fileview.cxx
+++ b/fpicker/source/office/fileview.cxx
@@ -45,6 +45,7 @@
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
#include <rtl/math.hxx>
+#include <o3tl/safeint.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <osl/mutex.hxx>
#include <osl/conditn.hxx>
@@ -1106,7 +1107,7 @@ void SvtFileView::SetConfigString(const OUString& rCfgStr)
--nItemId;
int nColumn = nItemId - 1;
- if (nColumn >= 0 && static_cast<unsigned int>(nColumn) < aWidths.size())
+ if (nColumn >= 0 && o3tl::make_unsigned(nColumn) < aWidths.size())
aWidths[nColumn] = nWidth;
}
diff --git a/framework/source/fwe/classes/addonsoptions.cxx b/framework/source/fwe/classes/addonsoptions.cxx
index 2fa0307e37d4..947cd4bf4862 100644
--- a/framework/source/fwe/classes/addonsoptions.cxx
+++ b/framework/source/fwe/classes/addonsoptions.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/beans/PropertyValue.hpp>
#include <framework/addonsoptions.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/configmgr.hxx>
#include <unotools/configitem.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -805,7 +806,7 @@ bool AddonsOptions_Impl::ReadToolBarItemSet( const OUString& rToolBarItemSetNode
}
}
- return ( static_cast<sal_uInt32>(rAddonOfficeToolBarSeq.getLength()) > nToolBarItemCount );
+ return ( o3tl::make_unsigned(rAddonOfficeToolBarSeq.getLength()) > nToolBarItemCount );
}
void AddonsOptions_Impl::ReadOfficeNotebookBarSet(
@@ -863,7 +864,7 @@ bool AddonsOptions_Impl::ReadNotebookBarItemSet(
}
}
- return (static_cast<sal_uInt32>(rAddonOfficeNotebookBarSeq.getLength())
+ return (o3tl::make_unsigned(rAddonOfficeNotebookBarSeq.getLength())
> nNotebookBarItemCount);
}
@@ -1256,7 +1257,7 @@ bool AddonsOptions_Impl::ReadMergeStatusbarData(
}
}
- return ( static_cast<sal_uInt32>(rMergeStatusbarItems.getLength()) > nStatusbarItemCount );
+ return ( o3tl::make_unsigned(rMergeStatusbarItems.getLength()) > nStatusbarItemCount );
}
bool AddonsOptions_Impl::ReadStatusBarItem(
diff --git a/framework/source/services/autorecovery.cxx b/framework/source/services/autorecovery.cxx
index 5aaeb12c6467..0bcd2c6befaf 100644
--- a/framework/source/services/autorecovery.cxx
+++ b/framework/source/services/autorecovery.cxx
@@ -71,6 +71,7 @@
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/propshlp.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <unotools/mediadescriptor.hxx>
#include <comphelper/namedvaluecollection.hxx>
@@ -4023,7 +4024,7 @@ bool AutoRecovery::impl_enoughDiscSpace(sal_Int32 nRequiredSpace)
}
sal_uInt64 nFreeMB = nFreeSpace/1048576;
- return (nFreeMB >= static_cast<sal_uInt64>(nRequiredSpace));
+ return (nFreeMB >= o3tl::make_unsigned(nRequiredSpace));
#endif // SIMULATE_FULL_DISC
}
diff --git a/framework/source/uielement/addonstoolbarmanager.cxx b/framework/source/uielement/addonstoolbarmanager.cxx
index 2c5071619306..3fc54f1ad00c 100644
--- a/framework/source/uielement/addonstoolbarmanager.cxx
+++ b/framework/source/uielement/addonstoolbarmanager.cxx
@@ -29,6 +29,7 @@
#include <com/sun/star/ui/DockingArea.hpp>
#include <com/sun/star/util/XUpdatable.hpp>
#include <comphelper/propertysequence.hxx>
+#include <o3tl/safeint.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <svtools/miscopt.hxx>
@@ -199,7 +200,7 @@ void AddonsToolBarManager::FillToolbar( const Sequence< Sequence< PropertyValue
sal_uInt32 nElements( 0 );
bool bAppendSeparator( false );
Reference< XWindow > xToolbarWindow = VCLUnoHelper::GetInterface( m_pToolBar );
- for ( sal_uInt32 n = 0; n < static_cast<sal_uInt32>(rAddonToolbar.getLength()); n++ )
+ for ( sal_uInt32 n = 0; n < o3tl::make_unsigned(rAddonToolbar.getLength()); n++ )
{
OUString aURL;
OUString aTitle;
diff --git a/framework/source/uifactory/addonstoolbarfactory.cxx b/framework/source/uifactory/addonstoolbarfactory.cxx
index 5e0dbc01861a..7607d20653d1 100644
--- a/framework/source/uifactory/addonstoolbarfactory.cxx
+++ b/framework/source/uifactory/addonstoolbarfactory.cxx
@@ -28,6 +28,7 @@
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
using namespace com::sun::star::uno;
@@ -112,14 +113,14 @@ bool AddonsToolBarFactory::hasButtonsInContext(
// Check before we create a toolbar that we have at least one button in
// the current frame context.
- for ( sal_uInt32 i = 0; i < static_cast<sal_uInt32>(rPropSeqSeq.getLength()); i++ )
+ for ( sal_uInt32 i = 0; i < o3tl::make_unsigned(rPropSeqSeq.getLength()); i++ )
{
bool bIsButton( true );
bool bIsCorrectContext( false );
sal_uInt32 nPropChecked( 0 );
const Sequence< PropertyValue >& rPropSeq = rPropSeqSeq[i];
- for ( sal_uInt32 j = 0; j < static_cast<sal_uInt32>(rPropSeq.getLength()); j++ )
+ for ( sal_uInt32 j = 0; j < o3tl::make_unsigned(rPropSeq.getLength()); j++ )
{
if ( rPropSeq[j].Name == "Context" )
{
diff --git a/hwpfilter/source/hwpfile.cxx b/hwpfilter/source/hwpfile.cxx
index a97c39cc8eb6..b7031bb10444 100644
--- a/hwpfilter/source/hwpfile.cxx
+++ b/hwpfilter/source/hwpfile.cxx
@@ -25,6 +25,9 @@
#include <stdlib.h>
#include <string.h>
#include <errno.h>
+
+#include <o3tl/safeint.hxx>
+
#include "hwplib.h"
#include "hwpfile.h"
#include "hiodev.h"
@@ -399,7 +402,7 @@ void HWPFile::TagsRead()
ColumnDef *HWPFile::GetColumnDef(int num)
{
- if (static_cast<size_t>(num) < columnlist.size())
+ if (o3tl::make_unsigned(num) < columnlist.size())
return columnlist[num]->xColdef.get();
else
return nullptr;
@@ -421,7 +424,7 @@ int HWPFile::GetPageMasterNum(int page)
HyperText *HWPFile::GetHyperText()
{
++currenthyper;
- if (static_cast<size_t>(currenthyper) <= hyperlist.size())
+ if (o3tl::make_unsigned(currenthyper) <= hyperlist.size())
return hyperlist[currenthyper-1].get();
else
return nullptr;
@@ -460,49 +463,49 @@ void HWPFile::AddBox(FBox * box)
ParaShape *HWPFile::getParaShape(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= pslist.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= pslist.size())
return nullptr;
return pslist[index].get();
}
CharShape *HWPFile::getCharShape(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= cslist.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= cslist.size())
return nullptr;
return cslist[index].get();
}
FBoxStyle *HWPFile::getFBoxStyle(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= fbslist.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= fbslist.size())
return nullptr;
return fbslist[index];
}
DateCode *HWPFile::getDateCode(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= datecodes.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= datecodes.size())
return nullptr;
return datecodes[index];
}
HeaderFooter *HWPFile::getHeaderFooter(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= headerfooters.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= headerfooters.size())
return nullptr;
return headerfooters[index];
}
ShowPageNum *HWPFile::getPageNumber(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= pagenumbers.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= pagenumbers.size())
return nullptr;
return pagenumbers[index];
}
Table *HWPFile::getTable(int index)
{
- if (index < 0 || static_cast<unsigned int>(index) >= tables.size())
+ if (index < 0 || o3tl::make_unsigned(index) >= tables.size())
return nullptr;
return tables[index].get();
}
diff --git a/hwpfilter/source/hwpreader.cxx b/hwpfilter/source/hwpreader.cxx
index 0cd9f831d59d..916017854364 100644
--- a/hwpfilter/source/hwpreader.cxx
+++ b/hwpfilter/source/hwpreader.cxx
@@ -23,6 +23,7 @@
#include "hwpreader.hxx"
#include <math.h>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tools/stream.hxx>
@@ -4355,7 +4356,7 @@ void HwpReader::makePictureDRAW(HWPDrawingObject *drawobj, Picture * hbox)
OUStringBuffer oustr;
if ((drawobj->u.freeform.npt > 2) &&
- (static_cast<size_t>(drawobj->u.freeform.npt) <
+ (o3tl::make_unsigned(drawobj->u.freeform.npt) <
(::std::numeric_limits<int>::max() / sizeof(double))))
{
int n, i;
diff --git a/i18npool/source/breakiterator/breakiterator_th.cxx b/i18npool/source/breakiterator/breakiterator_th.cxx
index 37948d5904b0..2504ab888884 100644
--- a/i18npool/source/breakiterator/breakiterator_th.cxx
+++ b/i18npool/source/breakiterator/breakiterator_th.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/i18n/CharacterIteratorMode.hpp>
+#include <o3tl/safeint.hxx>
#include <breakiterator_th.hxx>
#include <wtt.h>
@@ -187,7 +188,7 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos
{
if (Text != cachedText) {
cachedText = Text;
- if (m_aNextCellIndex.size() < size_t(cachedText.getLength())) {
+ if (m_aNextCellIndex.size() < o3tl::make_unsigned(cachedText.getLength())) {
m_aNextCellIndex.resize(cachedText.getLength());
m_aPreviousCellIndex.resize(cachedText.getLength());
}
@@ -209,10 +210,10 @@ void BreakIterator_th::makeIndex(const OUString& Text, sal_Int32 const nStartPos
sal_Int32 start, end, pos;
pos = start = end = startPos;
- assert(size_t(endPos) <= m_aNextCellIndex.size());
+ assert(endPos >= 0 && o3tl::make_unsigned(endPos) <= m_aNextCellIndex.size());
while (pos < endPos) {
end += getACell(str, start, endPos);
- assert(size_t(end) <= m_aNextCellIndex.size());
+ assert(end >= 0 && o3tl::make_unsigned(end) <= m_aNextCellIndex.size());
while (pos < end) {
m_aNextCellIndex[pos] = end;
m_aPreviousCellIndex[pos] = start;
diff --git a/idlc/source/idlccompile.cxx b/idlc/source/idlccompile.cxx
index 1cb84cc9fe8b..c2fc601142e2 100644
--- a/idlc/source/idlccompile.cxx
+++ b/idlc/source/idlccompile.cxx
@@ -21,6 +21,7 @@
#include <rtl/alloc.h>
#include <rtl/ustring.hxx>
#include <rtl/strbuf.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/process.h>
#include <osl/diagnose.h>
#include <osl/thread.h>
@@ -135,7 +136,7 @@ static OString makeTempName(const OString& prefix)
#if defined(_WIN32) || defined(SAL_UNX)
OSL_ASSERT( sizeof(tmpFilePattern) >
- static_cast<size_t>( tmpPath.getLength()
+ o3tl::make_unsigned( tmpPath.getLength()
+ RTL_CONSTASCII_LENGTH( PATH_SEPARATOR )
+ prefix.getLength()
+ RTL_CONSTASCII_LENGTH( "XXXXXX") ) );
diff --git a/include/oox/helper/helper.hxx b/include/oox/helper/helper.hxx
index 5a83c3780bc8..168116b9db84 100644
--- a/include/oox/helper/helper.hxx
+++ b/include/oox/helper/helper.hxx
@@ -25,6 +25,7 @@
#include <cstring>
#include <limits>
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <rtl/math.hxx>
#include <rtl/textenc.h>
@@ -36,10 +37,24 @@ namespace oox {
// Helper macros ==============================================================
+namespace detail {
+
+//TODO: Temporary helper for STATIC_ARRAY_SELECT; ultimately, the latter should be replaced by a
+// proper function (template):
+template<typename T> constexpr std::make_unsigned_t<T> make_unsigned(T value) {
+ if constexpr (std::is_signed_v<T>) {
+ return o3tl::make_unsigned(value);
+ } else {
+ return value;
+ }
+}
+
+}
+
/** Expands to the 'index'-th element of a STATIC data array, or to 'def', if
'index' is out of the array limits. */
#define STATIC_ARRAY_SELECT( array, index, def ) \
- ((static_cast<size_t>(index) < SAL_N_ELEMENTS(array)) ? ((array)[static_cast<size_t>(index)]) : (def))
+ ((detail::make_unsigned(index) < SAL_N_ELEMENTS(array)) ? ((array)[static_cast<size_t>(index)]) : (def))
// Common constants ===========================================================
diff --git a/linguistic/source/gciterator.cxx b/linguistic/source/gciterator.cxx
index 8d97abefcc6f..c0e56632df4b 100644
--- a/linguistic/source/gciterator.cxx
+++ b/linguistic/source/gciterator.cxx
@@ -44,6 +44,7 @@
#include <sal/config.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/conditn.hxx>
#include <cppuhelper/factory.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -257,7 +258,7 @@ sal_Bool SAL_CALL LngXStringKeyMap::hasValue(const OUString& aKey)
OUString SAL_CALL LngXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex)
{
- if (static_cast<sal_uInt32>(nIndex) >= maMap.size())
+ if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maMap.size())
throw css::lang::IndexOutOfBoundsException();
return OUString();
@@ -265,7 +266,7 @@ OUString SAL_CALL LngXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex)
css::uno::Any SAL_CALL LngXStringKeyMap::getValueByIndex(::sal_Int32 nIndex)
{
- if (static_cast<sal_uInt32>(nIndex) >= maMap.size())
+ if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maMap.size())
throw css::lang::IndexOutOfBoundsException();
return css::uno::Any();
diff --git a/oox/source/core/contexthandler2.cxx b/oox/source/core/contexthandler2.cxx
index 0d06647bfcd6..ef6075428554 100644
--- a/oox/source/core/contexthandler2.cxx
+++ b/oox/source/core/contexthandler2.cxx
@@ -22,6 +22,7 @@
#include <oox/token/namespaces.hxx>
#include <oox/token/tokens.hxx>
#include <rtl/ustrbuf.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
namespace oox::core {
@@ -74,7 +75,7 @@ sal_Int32 ContextHandler2Helper::getCurrentElement() const
sal_Int32 ContextHandler2Helper::getParentElement( sal_Int32 nCountBack ) const
{
- if( (nCountBack < 0) || (mxContextStack->size() < static_cast< size_t >( nCountBack )) )
+ if( (nCountBack < 0) || (mxContextStack->size() < o3tl::make_unsigned( nCountBack )) )
return XML_TOKEN_INVALID;
return (mxContextStack->size() == static_cast< size_t >( nCountBack )) ?
XML_ROOT_CONTEXT : (*mxContextStack)[ mxContextStack->size() - nCountBack - 1 ].mnElement;
diff --git a/oox/source/export/drawingml.cxx b/oox/source/export/drawingml.cxx
index 03ca4c8bd243..b4c37d514ece 100644
--- a/oox/source/export/drawingml.cxx
+++ b/oox/source/export/drawingml.cxx
@@ -99,6 +99,7 @@
#include <comphelper/storagehelper.hxx>
#include <comphelper/xmltools.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/stream.hxx>
#include <unotools/fontdefs.hxx>
#include <vcl/cvtgrf.hxx>
@@ -3011,7 +3012,7 @@ void DrawingML::WritePresetShape( const char* pShape, MSO_SPT eShapeType, bool b
sal_Int32 nValue, nLength = aAdjustmentSeq.getLength();
// aAdjustments will give info about the number of adj values for a particular geometry. For example for hexagon aAdjustments.size() will be 2 and for circular arrow it will be 5 as per lcl_getAdjNames.
// Sometimes there are more values than needed, so we ignore the excessive ones.
- if (aAdjustments.size() <= static_cast<sal_uInt32>(nLength))
+ if (aAdjustments.size() <= o3tl::make_unsigned(nLength))
{
for (sal_Int32 i = 0; i < static_cast<sal_Int32>(aAdjustments.size()); i++)
{
diff --git a/opencl/source/opencl_device.cxx b/opencl/source/opencl_device.cxx
index fe6f92a34ee6..1b6800e0ef8c 100644
--- a/opencl/source/opencl_device.cxx
+++ b/opencl/source/opencl_device.cxx
@@ -14,6 +14,7 @@
#include <algorithm>
#include <comphelper/random.hxx>
+#include <o3tl/safeint.hxx>
#include <opencl/openclconfig.hxx>
#include <opencl/platforminfo.hxx>
#include <sal/log.hxx>
@@ -593,7 +594,7 @@ ds_device const & getDeviceSelection(
}
/* Final device selection */
- if (bestDeviceIdx >=0 && static_cast< std::vector<ds_device>::size_type> ( bestDeviceIdx ) < aProfile->devices.size() )
+ if (bestDeviceIdx >=0 && o3tl::make_unsigned( bestDeviceIdx ) < aProfile->devices.size() )
{
selectedDevice = aProfile->devices[bestDeviceIdx];
bIsDeviceSelected = true;
diff --git a/reportdesign/source/filter/xml/xmlTable.cxx b/reportdesign/source/filter/xml/xmlTable.cxx
index 5c400a33512d..a960beaf442e 100644
--- a/reportdesign/source/filter/xml/xmlTable.cxx
+++ b/reportdesign/source/filter/xml/xmlTable.cxx
@@ -18,6 +18,7 @@
*/
#include "xmlTable.hxx"
#include "xmlfilter.hxx"
+#include <o3tl/safeint.hxx>
#include <xmloff/xmltoken.hxx>
#include <xmloff/xmlnmspe.hxx>
#include <xmloff/nmspmap.hxx>
@@ -223,7 +224,7 @@ void OXMLTable::endFastElement(sal_Int32 )
{
if ( xFixedLine->getOrientation() == 1 ) // vertical
{
- OSL_ENSURE(static_cast<sal_uInt32>(j+1) < m_aWidth.size(),"Illegal pos of col iter. There should be an empty cell for the next line part.");
+ OSL_ENSURE(o3tl::make_unsigned(j+1) < m_aWidth.size(),"Illegal pos of col iter. There should be an empty cell for the next line part.");
nWidth += m_aWidth[j+1];
if ( nWidth < MIN_WIDTH )
nWidth = MIN_WIDTH;
@@ -258,9 +259,9 @@ void OXMLTable::endFastElement(sal_Int32 )
void OXMLTable::addCell(const Reference<XReportComponent>& _xElement)
{
uno::Reference<report::XShape> xShape(_xElement,uno::UNO_QUERY);
- OSL_ENSURE(static_cast<sal_uInt32>(m_nRowIndex-1 ) < m_aGrid.size() && static_cast<sal_uInt32>( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size(),
+ OSL_ENSURE(o3tl::make_unsigned(m_nRowIndex-1 ) < m_aGrid.size() && o3tl::make_unsigned( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size(),
"OXMLTable::addCell: Invalid column and row index");
- if ( static_cast<sal_uInt32>(m_nRowIndex-1 ) < m_aGrid.size() && static_cast<sal_uInt32>( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size() )
+ if ( o3tl::make_unsigned(m_nRowIndex-1 ) < m_aGrid.size() && o3tl::make_unsigned( m_nColumnIndex-1 ) < m_aGrid[m_nRowIndex-1].size() )
{
TCell& rCell = m_aGrid[m_nRowIndex-1][m_nColumnIndex-1];
if ( _xElement.is() )
diff --git a/reportdesign/source/ui/dlg/CondFormat.cxx b/reportdesign/source/ui/dlg/CondFormat.cxx
index 016aa868cbae..c7a64b297d46 100644
--- a/reportdesign/source/ui/dlg/CondFormat.cxx
+++ b/reportdesign/source/ui/dlg/CondFormat.cxx
@@ -29,7 +29,7 @@
#include <com/sun/star/beans/XPropertySet.hpp>
#include <com/sun/star/lang/IllegalArgumentException.hpp>
-
+#include <o3tl/safeint.hxx>
#include <toolkit/helper/vclunohelper.hxx>
#include <vcl/settings.hxx>
@@ -145,7 +145,7 @@ namespace rptui
{
try
{
- if ( _nNewCondIndex > static_cast<size_t>(m_xCopy->getCount()) )
+ if ( _nNewCondIndex > o3tl::make_unsigned(m_xCopy->getCount()) )
throw IllegalArgumentException();
Reference< XFormatCondition > xCond = m_xCopy->createFormatCondition();
diff --git a/reportdesign/source/ui/inspection/GeometryHandler.cxx b/reportdesign/source/ui/inspection/GeometryHandler.cxx
index fb7bdb9e503c..34458e378756 100644
--- a/reportdesign/source/ui/inspection/GeometryHandler.cxx
+++ b/reportdesign/source/ui/inspection/GeometryHandler.cxx
@@ -106,6 +106,7 @@
#include <helpids.h>
#include <toolkit/helper/convert.hxx>
#include <o3tl/functional.hxx>
+#include <o3tl/safeint.hxx>
#define DATA_OR_FORMULA 0
#define FUNCTION 1
@@ -1257,7 +1258,7 @@ uno::Any SAL_CALL GeometryHandler::convertToControlValue(const OUString & Proper
{
sal_Int16 nParagraphAdjust = sal_Int16(style::ParagraphAdjust_LEFT);
aPropertyValue >>= nParagraphAdjust;
- if (static_cast<sal_uInt32>(nParagraphAdjust) < SAL_N_ELEMENTS(RID_STR_PARAADJUST_CONST) - 1)
+ if (o3tl::make_unsigned(nParagraphAdjust) < SAL_N_ELEMENTS(RID_STR_PARAADJUST_CONST) - 1)
aControlValue <<= RptResId(RID_STR_PARAADJUST_CONST[nParagraphAdjust]);
}
break;
diff --git a/reportdesign/source/ui/misc/FunctionHelper.cxx b/reportdesign/source/ui/misc/FunctionHelper.cxx
index f42e65cc204b..00043d4a94fd 100644
--- a/reportdesign/source/ui/misc/FunctionHelper.cxx
+++ b/reportdesign/source/ui/misc/FunctionHelper.cxx
@@ -19,6 +19,7 @@
#include <FunctionHelper.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <formula/funcvarargs.h>
@@ -236,21 +237,21 @@ sal_uInt32 FunctionDescription::getVarArgsStart() const
OUString FunctionDescription::getParameterName(sal_uInt32 _nPos) const
{
- if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
+ if ( _nPos < o3tl::make_unsigned(m_aParameter.getLength()) )
return m_aParameter[_nPos].Name;
return OUString();
}
OUString FunctionDescription::getParameterDescription(sal_uInt32 _nPos) const
{
- if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
+ if ( _nPos < o3tl::make_unsigned(m_aParameter.getLength()) )
return m_aParameter[_nPos].Description;
return OUString();
}
bool FunctionDescription::isParameterOptional(sal_uInt32 _nPos) const
{
- if ( _nPos < static_cast<sal_uInt32>(m_aParameter.getLength()) )
+ if ( _nPos < o3tl::make_unsigned(m_aParameter.getLength()) )
return m_aParameter[_nPos].IsOptional;
return false;
}
diff --git a/sal/osl/unx/file.cxx b/sal/osl/unx/file.cxx
index 501d9bd1e0b9..aa293f914d74 100644
--- a/sal/osl/unx/file.cxx
+++ b/sal/osl/unx/file.cxx
@@ -18,6 +18,7 @@
*/
#include <config_features.h>
+#include <o3tl/safeint.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <sal/log.hxx>
#include <osl/diagnose.h>
@@ -331,7 +332,7 @@ oslFileError FileHandle_Impl::readAt(
m_offset = nOffset;
- if (static_cast<sal_uInt64>(m_offset) >= m_size)
+ if (o3tl::make_unsigned(m_offset) >= m_size)
{
nBytes = 0;
}
diff --git a/sal/osl/unx/file_url.cxx b/sal/osl/unx/file_url.cxx
index 513b8661d406..011998838db2 100644
--- a/sal/osl/unx/file_url.cxx
+++ b/sal/osl/unx/file_url.cxx
@@ -32,6 +32,7 @@
#include <strings.h>
#include <unistd.h>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <osl/security.hxx>
#include <osl/socket.h>
@@ -834,7 +835,7 @@ oslFileError FileURLToPath(char * buffer, size_t bufLen, rtl_uString* ustrFileUR
osl_systemPathRemoveSeparator(strSystemPath.pData);
- if (sal_uInt32(strSystemPath.getLength()) >= bufLen) {
+ if (o3tl::make_unsigned(strSystemPath.getLength()) >= bufLen) {
return osl_File_E_OVERFLOW;
}
std::strcpy(buffer, strSystemPath.getStr());
diff --git a/sal/osl/unx/pipe.cxx b/sal/osl/unx/pipe.cxx
index d601b6531531..153db04d99fa 100644
--- a/sal/osl/unx/pipe.cxx
+++ b/sal/osl/unx/pipe.cxx
@@ -19,6 +19,7 @@
#include "system.hxx"
+#include <o3tl/safeint.hxx>
#include <osl/pipe.h>
#include <osl/diagnose.h>
#include <osl/thread.h>
@@ -172,7 +173,7 @@ static oslPipe osl_psz_createPipe(const char *pszPipeName, oslPipeOptions Option
name += OStringLiteral("OSL_PIPE_") + pszPipeName;
}
- if (sal_uInt32(name.getLength()) >= sizeof addr.sun_path)
+ if (o3tl::make_unsigned(name.getLength()) >= sizeof addr.sun_path)
{
SAL_WARN("sal.osl.pipe", "osl_createPipe: pipe name too long");
return nullptr;
diff --git a/sal/osl/unx/security.cxx b/sal/osl/unx/security.cxx
index 23b8046dbcb5..f6fc52ce5398 100644
--- a/sal/osl/unx/security.cxx
+++ b/sal/osl/unx/security.cxx
@@ -32,6 +32,7 @@
#include "system.hxx"
+#include <o3tl/safeint.hxx>
#include <osl/security.h>
#include <rtl/bootstrap.hxx>
#include <sal/log.hxx>
@@ -68,7 +69,7 @@ static bool sysconf_SC_GETPW_R_SIZE_MAX(std::size_t * value) {
way and always set EINVAL, so be resilient here: */
return false;
}
- SAL_WARN_IF( m < 0 || static_cast<unsigned long>(m) >= std::numeric_limits<std::size_t>::max(), "sal.osl",
+ SAL_WARN_IF( m < 0 || o3tl::make_unsigned(m) >= std::numeric_limits<std::size_t>::max(), "sal.osl",
"m < 0 || (unsigned long) m >= std::numeric_limits<std::size_t>::max()");
*value = static_cast<std::size_t>(m);
return true;
@@ -235,7 +236,7 @@ sal_Bool SAL_CALL osl_getUserName(oslSecurity Security, rtl_uString **ustrName)
if (pSecImpl != nullptr && pSecImpl->m_pPasswd.pw_name != nullptr) {
pszName = pSecImpl->m_pPasswd.pw_name;
auto const n = std::strlen(pszName);
- if (n <= sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
+ if (n <= o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max())) {
len = n;
bRet = true;
}
@@ -353,7 +354,7 @@ static bool osl_psz_getHomeDir(oslSecurity Security, OString* pszDirectory)
if (pStr != nullptr && pStr[0] != '\0' && access(pStr, 0) == 0)
{
auto const len = std::strlen(pStr);
- if (len > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
+ if (len > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max())) {
return false;
}
*pszDirectory = OString(pStr, len);
@@ -363,7 +364,7 @@ static bool osl_psz_getHomeDir(oslSecurity Security, OString* pszDirectory)
if (pSecImpl->m_pPasswd.pw_dir != nullptr)
{
auto const len = std::strlen(pSecImpl->m_pPasswd.pw_dir);
- if (len > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
+ if (len > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max())) {
return false;
}
*pszDirectory = OString(pSecImpl->m_pPasswd.pw_dir, len);
@@ -472,7 +473,7 @@ static bool osl_psz_getConfigDir(oslSecurity Security, OString* pszDirectory)
else
{
auto const len = std::strlen(pStr);
- if (len > sal_uInt32(std::numeric_limits<sal_Int32>::max())) {
+ if (len > o3tl::make_unsigned(std::numeric_limits<sal_Int32>::max())) {
return false;
}
*pszDirectory = OString(pStr, len);
diff --git a/sal/textenc/converter.cxx b/sal/textenc/converter.cxx
index 92eca3fc190a..60e6a3383708 100644
--- a/sal/textenc/converter.cxx
+++ b/sal/textenc/converter.cxx
@@ -19,6 +19,7 @@
#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <rtl/textcvt.h>
#include <sal/types.h>
@@ -141,7 +142,7 @@ sal::detail::textenc::handleBadInputUnicodeToTextConversion(
cReplace = '_';
break;
}
- if (static_cast<sal_Size>(pDestBufEnd - *pDestBufPtr) > nPrefixLen)
+ if (o3tl::make_unsigned(pDestBufEnd - *pDestBufPtr) > nPrefixLen)
{
while (nPrefixLen-- > 0)
*(*pDestBufPtr)++ = *pPrefix++;
diff --git a/sc/source/core/data/column.cxx b/sc/source/core/data/column.cxx
index 5d3cbcbd99e7..36432e9f3358 100644
--- a/sc/source/core/data/column.cxx
+++ b/sc/source/core/data/column.cxx
@@ -49,6 +49,7 @@
#include <svl/sharedstringpool.hxx>
#include <editeng/fieldupdater.hxx>
#include <formula/errorcodes.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <map>
@@ -841,11 +842,11 @@ bool ScColumn::TestInsertRow( SCROW nStartRow, SCSIZE nSize ) const
if (it->type == sc::element_type_empty)
nLastNonEmptyRow -= it->size;
- if (nLastNonEmptyRow < static_cast<size_t>(nStartRow))
+ if (nLastNonEmptyRow < o3tl::make_unsigned(nStartRow))
// No cells would get pushed out.
return pAttrArray->TestInsertRow(nSize);
- if (nLastNonEmptyRow + nSize > static_cast<size_t>(GetDoc()->MaxRow()))
+ if (nLastNonEmptyRow + nSize > o3tl::make_unsigned(GetDoc()->MaxRow()))
// At least one cell would get pushed out. Not good.
return false;
@@ -983,7 +984,7 @@ public:
maDestPos.miCellPos = aPos.first;
sc::SharedFormulaUtil::joinFormulaCellAbove(aPos);
size_t nLastRow = nTopRow + nDataSize;
- if (nLastRow < static_cast<size_t>(mrSrcDoc.MaxRow()))
+ if (nLastRow < o3tl::make_unsigned(mrSrcDoc.MaxRow()))
{
aPos = rDestCells.position(maDestPos.miCellPos, nLastRow+1);
sc::SharedFormulaUtil::joinFormulaCellAbove(aPos);
@@ -1069,11 +1070,11 @@ void ScColumn::CopyStaticToDocument(
size_t nDataSize = 0;
size_t nCurRow = nRow1;
- for (; it != maCells.end() && nCurRow <= static_cast<size_t>(nRow2); ++it, nOffset = 0, nCurRow += nDataSize)
+ for (; it != maCells.end() && nCurRow <= o3tl::make_unsigned(nRow2); ++it, nOffset = 0, nCurRow += nDataSize)
{
bool bLastBlock = false;
nDataSize = it->size - nOffset;
- if (nCurRow + nDataSize - 1 > static_cast<size_t>(nRow2))
+ if (nCurRow + nDataSize - 1 > o3tl::make_unsigned(nRow2))
{
// Truncate the block to copy to clipboard.
nDataSize = nRow2 - nCurRow + 1;
diff --git a/sc/source/core/data/column2.cxx b/sc/source/core/data/column2.cxx
index d3db033b63f2..10e09421fa98 100644
--- a/sc/source/core/data/column2.cxx
+++ b/sc/source/core/data/column2.cxx
@@ -44,7 +44,7 @@
#include <recursionhelper.hxx>
#include <editeng/eeitem.hxx>
-
+#include <o3tl/safeint.hxx>
#include <svx/algitem.hxx>
#include <editeng/editobj.hxx>
#include <editeng/editstat.hxx>
@@ -2710,7 +2710,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
{
case sc::element_type_numeric:
{
- if (static_cast<size_t>(nRow2) < itBlk->size)
+ if (o3tl::make_unsigned(nRow2) < itBlk->size)
{
// Requested range falls within the first block. No need to cache.
const double* p = &sc::numeric_block::at(*itBlk->data, nRow1);
@@ -2757,7 +2757,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
// Failed to insert a new cached column array.
return formula::VectorRefArray();
- if (static_cast<size_t>(nRow2) < itBlk->size)
+ if (o3tl::make_unsigned(nRow2) < itBlk->size)
{
// Requested range falls within the first block.
copyFirstStringBlock(*pDocument, rArray, nRow2+1, itBlk);
@@ -2789,7 +2789,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
break;
case sc::element_type_formula:
{
- if (static_cast<size_t>(nRow2) < itBlk->size)
+ if (o3tl::make_unsigned(nRow2) < itBlk->size)
{
// Requested length is within a single block, and the data is
// not cached.
@@ -2844,7 +2844,7 @@ formula::VectorRefArray ScColumn::FetchVectorRefArray( SCROW nRow1, SCROW nRow2
// Failed to insert a new cached column array.
return formula::VectorRefArray(formula::VectorRefArray::Invalid);
- if (static_cast<size_t>(nRow2) < itBlk->size)
+ if (o3tl::make_unsigned(nRow2) < itBlk->size)
return formula::VectorRefArray(&(*pColArray->mpNumArray)[nRow1]);
// Fill the remaining array with values from the following blocks.
diff --git a/sc/source/core/data/column4.cxx b/sc/source/core/data/column4.cxx
index 6bb39705079b..fed5e01c3e3a 100644
--- a/sc/source/core/data/column4.cxx
+++ b/sc/source/core/data/column4.cxx
@@ -30,6 +30,7 @@
#include <compiler.hxx>
#include <recursionhelper.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/sharedstringpool.hxx>
#include <sal/log.hxx>
#include <tools/stream.hxx>
@@ -728,13 +729,13 @@ public:
sc::cellnote_block::const_iterator it = sc::cellnote_block::begin(*node.data);
sc::cellnote_block::const_iterator itEnd = sc::cellnote_block::end(*node.data);
size_t nOffset = 0;
- if(nTopRow < size_t(mnStartRow))
+ if(nTopRow < o3tl::make_unsigned(mnStartRow))
{
std::advance(it, mnStartRow - nTopRow);
nOffset = mnStartRow - nTopRow;
}
- for (; it != itEnd && nTopRow + nOffset <= size_t(mnEndRow);
+ for (; it != itEnd && nTopRow + nOffset <= o3tl::make_unsigned(mnEndRow);
++it, ++nOffset)
{
ScAddress aPos(mnCol, nTopRow + nOffset, mnTab);
@@ -1336,7 +1337,7 @@ public:
SCROW nBackTrackSize = pFC->aPos.Row() - pFC->GetSharedTopRow();
if (nBackTrackSize > 0)
{
- assert(static_cast<size_t>(nBackTrackSize) <= nOffset);
+ assert(o3tl::make_unsigned(nBackTrackSize) <= nOffset);
for (SCROW i = 0; i < nBackTrackSize; ++i)
--pp;
endListening(mrEndCxt, pp, ppBeg);
@@ -1413,7 +1414,7 @@ public:
SCROW nBackTrackSize = pFC->aPos.Row() - pFC->GetSharedTopRow();
if (nBackTrackSize > 0)
{
- assert(static_cast<size_t>(nBackTrackSize) <= nOffset);
+ assert(o3tl::make_unsigned(nBackTrackSize) <= nOffset);
for (SCROW i = 0; i < nBackTrackSize; ++i)
--pp;
mnStartRow -= nBackTrackSize;
diff --git a/sc/source/core/data/columnspanset.cxx b/sc/source/core/data/columnspanset.cxx
index 849783b5bce5..5d605dc79b2b 100644
--- a/sc/source/core/data/columnspanset.cxx
+++ b/sc/source/core/data/columnspanset.cxx
@@ -19,6 +19,8 @@
#include <algorithm>
#include <memory>
+#include <o3tl/safeint.hxx>
+
namespace sc {
namespace {
@@ -64,14 +66,14 @@ ColumnSpanSet::~ColumnSpanSet()
ColumnSpanSet::ColumnType& ColumnSpanSet::getColumn(const ScDocument& rDoc, SCTAB nTab, SCCOL nCol)
{
- if (static_cast<size_t>(nTab) >= maTables.size())
+ if (o3tl::make_unsigned(nTab) >= maTables.size())
maTables.resize(nTab+1);
if (!maTables[nTab])
maTables[nTab].reset(new TableType);
TableType& rTab = *maTables[nTab];
- if (static_cast<size_t>(nCol) >= rTab.size())
+ if (o3tl::make_unsigned(nCol) >= rTab.size())
rTab.resize(nCol+1);
if (!rTab[nCol])
diff --git a/sc/source/core/data/dociter.cxx b/sc/source/core/data/dociter.cxx
index bad6d64ff7c8..2308a8477e20 100644
--- a/sc/source/core/data/dociter.cxx
+++ b/sc/source/core/data/dociter.cxx
@@ -39,6 +39,7 @@
#include <scmatrix.hxx>
#include <rowheightcontext.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/fract.hxx>
#include <editeng/editobj.hxx>
#include <svl/sharedstring.hxx>
@@ -2229,7 +2230,7 @@ SCROW ScHorizontalCellIterator::FindNextNonEmptyRow()
for (const ColParam& r : maColPositions)
{
- assert(static_cast<size_t>(mnRow) <= r.maPos->position);
+ assert(o3tl::make_unsigned(mnRow) <= r.maPos->position);
nNextRow = std::min (nNextRow, static_cast<size_t>(r.maPos->position));
}
diff --git a/sc/source/core/data/documen2.cxx b/sc/source/core/data/documen2.cxx
index 4b6e7fac9b0f..36b4d2d0556a 100644
--- a/sc/source/core/data/documen2.cxx
+++ b/sc/source/core/data/documen2.cxx
@@ -20,6 +20,7 @@
#include <scextopt.hxx>
#include <autonamecache.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/thread.h>
#include <svx/xtable.hxx>
#include <sfx2/bindings.hxx>
@@ -526,7 +527,7 @@ void ScDocument::ResetClip( ScDocument* pSourceDoc, SCTAB nTab )
void ScDocument::EnsureTable( SCTAB nTab )
{
bool bExtras = !bIsUndo; // Column-Widths, Row-Heights, Flags
- if (static_cast<size_t>(nTab) >= maTabs.size())
+ if (o3tl::make_unsigned(nTab) >= maTabs.size())
maTabs.resize(nTab+1);
if (!maTabs[nTab])
diff --git a/sc/source/core/data/document.cxx b/sc/source/core/data/document.cxx
index 9a36ed567d90..7366d6702a95 100644
--- a/sc/source/core/data/document.cxx
+++ b/sc/source/core/data/document.cxx
@@ -21,6 +21,7 @@
#include <editeng/boxitem.hxx>
#include <editeng/editobj.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/sdrundomanager.hxx>
#include <svx/svditer.hxx>
#include <sfx2/objsh.hxx>
@@ -1758,7 +1759,7 @@ bool ScDocument::HasPartOfMerged( const ScRange& rRange )
size_t ScDocument::GetFormulaHash( const ScAddress& rPos ) const
{
SCTAB nTab = rPos.Tab();
- if (!ValidTab(nTab) || static_cast<size_t>(nTab) >= maTabs.size() || !maTabs[nTab])
+ if (!ValidTab(nTab) || o3tl::make_unsigned(nTab) >= maTabs.size() || !maTabs[nTab])
return 0;
return maTabs[nTab]->GetFormulaHash(rPos.Col(), rPos.Row());
@@ -1767,7 +1768,7 @@ size_t ScDocument::GetFormulaHash( const ScAddress& rPos ) const
ScFormulaVectorState ScDocument::GetFormulaVectorState( const ScAddress& rPos ) const
{
SCTAB nTab = rPos.Tab();
- if (!ValidTab(nTab) || static_cast<size_t>(nTab) >= maTabs.size() || !maTabs[nTab])
+ if (!ValidTab(nTab) || o3tl::make_unsigned(nTab) >= maTabs.size() || !maTabs[nTab])
return FormulaVectorUnknown;
return maTabs[nTab]->GetFormulaVectorState(rPos.Col(), rPos.Row());
@@ -2500,7 +2501,7 @@ void ScDocument::DumpAreaBroadcasters() const
bool ScDocument::TableExists( SCTAB nTab ) const
{
- return ValidTab(nTab) && static_cast<size_t>(nTab) < maTabs.size() && maTabs[nTab];
+ return ValidTab(nTab) && o3tl::make_unsigned(nTab) < maTabs.size() && maTabs[nTab];
}
ScTable* ScDocument::FetchTable( SCTAB nTab )
@@ -4807,7 +4808,7 @@ void ScDocument::ApplyPatternIfNumberformatIncompatible( const ScRange& rRange,
void ScDocument::AddCondFormatData( const ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex )
{
- if(static_cast<size_t>(nTab) >= maTabs.size())
+ if(o3tl::make_unsigned(nTab) >= maTabs.size())
return;
if(!maTabs[nTab])
@@ -4818,7 +4819,7 @@ void ScDocument::AddCondFormatData( const ScRangeList& rRange, SCTAB nTab, sal_u
void ScDocument::RemoveCondFormatData( const ScRangeList& rRange, SCTAB nTab, sal_uInt32 nIndex )
{
- if(static_cast<size_t>(nTab) >= maTabs.size())
+ if(o3tl::make_unsigned(nTab) >= maTabs.size())
return;
if(!maTabs[nTab])
diff --git a/sc/source/core/data/documentimport.cxx b/sc/source/core/data/documentimport.cxx
index 2fd7f744d34c..83429a587a9e 100644
--- a/sc/source/core/data/documentimport.cxx
+++ b/sc/source/core/data/documentimport.cxx
@@ -24,6 +24,7 @@
#include <bcaslot.hxx>
#include <scopetools.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/sharedstringpool.hxx>
#include <svl/languageoptions.hxx>
#include <unotools/configmgr.hxx>
@@ -59,7 +60,7 @@ struct ScDocumentImportImpl
bool isValid( size_t nTab, size_t nCol )
{
- return (nTab <= size_t(MAXTAB) && nCol <= size_t(mrDoc.MaxCol()));
+ return (nTab <= o3tl::make_unsigned(MAXTAB) && nCol <= o3tl::make_unsigned(mrDoc.MaxCol()));
}
ColAttr* getColAttr( size_t nTab, size_t nCol )
@@ -82,7 +83,7 @@ struct ScDocumentImportImpl
if (!isValid(nTab, nCol))
return nullptr;
- if (size_t(nTab) >= maBlockPosSet.size())
+ if (o3tl::make_unsigned(nTab) >= maBlockPosSet.size())
{
for (SCTAB i = maBlockPosSet.size(); i <= nTab; ++i)
maBlockPosSet.emplace_back(mrDoc, i);
diff --git a/sc/source/core/data/dpcache.cxx b/sc/source/core/data/dpcache.cxx
index d86ab2a300be..60b8a2f87d24 100644
--- a/sc/source/core/data/dpcache.cxx
+++ b/sc/source/core/data/dpcache.cxx
@@ -39,6 +39,7 @@
#include <unotools/localedatawrapper.hxx>
#include <unotools/collatorwrapper.hxx>
#include <svl/zforlist.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#if DUMP_PIVOT_TABLE
@@ -962,7 +963,7 @@ SCROW ScDPCache::GetItemDataId(sal_uInt16 nDim, SCROW nRow, bool bRepeatIfEmpty)
OSL_ENSURE(nDim < mnColumnCount, "ScDPTableDataCache::GetItemDataId ");
const Field& rField = *maFields[nDim];
- if (static_cast<size_t>(nRow) >= rField.maData.size())
+ if (o3tl::make_unsigned(nRow) >= rField.maData.size())
{
// nRow is in the trailing empty rows area.
if (bRepeatIfEmpty)
@@ -1151,7 +1152,7 @@ SCROW ScDPCache::GetIdByItemData(long nDim, const ScDPItemData& rItem) const
// group field.
nDim -= mnColumnCount;
- if (static_cast<size_t>(nDim) < maGroupFields.size())
+ if (o3tl::make_unsigned(nDim) < maGroupFields.size())
{
const ScDPItemDataVec& rGI = maGroupFields[nDim]->maItems;
for (size_t i = 0, n = rGI.size(); i < n; ++i)
diff --git a/sc/source/core/data/dpfilteredcache.cxx b/sc/source/core/data/dpfilteredcache.cxx
index a0fce6afdbbc..a95144ee5f9a 100644
--- a/sc/source/core/data/dpfilteredcache.cxx
+++ b/sc/source/core/data/dpfilteredcache.cxx
@@ -23,7 +23,7 @@
#include <queryparam.hxx>
#include <dpitemdata.hxx>
#include <com/sun/star/uno/Sequence.hxx>
-
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <algorithm>
@@ -281,7 +281,7 @@ OUString ScDPFilteredCache::getFieldName(SCCOL nIndex) const
const ::std::vector<SCROW>& ScDPFilteredCache::getFieldEntries( sal_Int32 nColumn ) const
{
- if (nColumn < 0 || static_cast<size_t>(nColumn) >= maFieldEntries.size())
+ if (nColumn < 0 || o3tl::make_unsigned(nColumn) >= maFieldEntries.size())
{
// index out of bound. Hopefully this code will never be reached.
static const ::std::vector<SCROW> emptyEntries{};
diff --git a/sc/source/core/data/dpoutput.cxx b/sc/source/core/data/dpoutput.cxx
index 60b423aec6c6..e0636a38d136 100644
--- a/sc/source/core/data/dpoutput.cxx
+++ b/sc/source/core/data/dpoutput.cxx
@@ -22,6 +22,7 @@
#include <editeng/boxitem.hxx>
#include <editeng/wghtitem.hxx>
#include <editeng/justifyitem.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <svl/itemset.hxx>
@@ -1559,7 +1560,7 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
// test for column header
- if ( nRow == nTabStartRow && nCol >= nDataStartCol && static_cast<size_t>(nCol) < nDataStartCol + pColFields.size())
+ if ( nRow == nTabStartRow && nCol >= nDataStartCol && o3tl::make_unsigned(nCol) < nDataStartCol + pColFields.size())
{
rOrient = sheet::DataPilotFieldOrientation_COLUMN;
long nField = nCol - nDataStartCol;
@@ -1568,7 +1569,7 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
// test for row header
- if ( nRow+1 == nDataStartRow && nCol >= nTabStartCol && static_cast<size_t>(nCol) < nTabStartCol + pRowFields.size() )
+ if ( nRow+1 == nDataStartRow && nCol >= nTabStartCol && o3tl::make_unsigned(nCol) < nTabStartCol + pRowFields.size() )
{
rOrient = sheet::DataPilotFieldOrientation_ROW;
long nField = nCol - nTabStartCol;
@@ -1578,7 +1579,7 @@ long ScDPOutput::GetHeaderDim( const ScAddress& rPos, sheet::DataPilotFieldOrien
// test for page field
SCROW nPageStartRow = aStartPos.Row() + ( bDoFilter ? 1 : 0 );
- if ( nCol == aStartPos.Col() && nRow >= nPageStartRow && static_cast<size_t>(nRow) < nPageStartRow + pPageFields.size() )
+ if ( nCol == aStartPos.Col() && nRow >= nPageStartRow && o3tl::make_unsigned(nRow) < nPageStartRow + pPageFields.size() )
{
rOrient = sheet::DataPilotFieldOrientation_PAGE;
long nField = nRow - nPageStartRow;
@@ -1610,7 +1611,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
// test for column header
if ( nCol >= nDataStartCol && nCol <= nTabEndCol &&
- nRow + 1 >= nMemberStartRow && static_cast<size_t>(nRow) < nMemberStartRow + pColFields.size())
+ nRow + 1 >= nMemberStartRow && o3tl::make_unsigned(nRow) < nMemberStartRow + pColFields.size())
{
long nField = nRow - nMemberStartRow;
if (nField < 0)
@@ -1626,7 +1627,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
bool bFound = false; // is this within the same orientation?
bool bBeforeDrag = false;
bool bAfterDrag = false;
- for (long nPos=0; static_cast<size_t>(nPos)<pColFields.size() && !bFound; nPos++)
+ for (long nPos=0; o3tl::make_unsigned(nPos)<pColFields.size() && !bFound; nPos++)
{
if (pColFields[nPos].mnDim == nDragDim)
{
@@ -1669,7 +1670,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
pRowFields.empty() && nCol == nTabStartCol && bMouseLeft );
if ( bSpecial || ( nRow+1 >= nDataStartRow && nRow <= nTabEndRow &&
- nCol + 1 >= nTabStartCol && static_cast<size_t>(nCol) < nTabStartCol + pRowFields.size() ) )
+ nCol + 1 >= nTabStartCol && o3tl::make_unsigned(nCol) < nTabStartCol + pRowFields.size() ) )
{
long nField = nCol - nTabStartCol;
//TODO: find start of dimension
@@ -1680,7 +1681,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
bool bFound = false; // is this within the same orientation?
bool bBeforeDrag = false;
bool bAfterDrag = false;
- for (long nPos=0; static_cast<size_t>(nPos)<pRowFields.size() && !bFound; nPos++)
+ for (long nPos=0; o3tl::make_unsigned(nPos)<pRowFields.size() && !bFound; nPos++)
{
if (pRowFields[nPos].mnDim == nDragDim)
{
@@ -1720,7 +1721,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
SCROW nPageStartRow = aStartPos.Row() + ( bDoFilter ? 1 : 0 );
if ( nCol >= aStartPos.Col() && nCol <= nTabEndCol &&
- nRow + 1 >= nPageStartRow && static_cast<size_t>(nRow) < nPageStartRow + pPageFields.size() )
+ nRow + 1 >= nPageStartRow && o3tl::make_unsigned(nRow) < nPageStartRow + pPageFields.size() )
{
long nField = nRow - nPageStartRow;
if (nField < 0)
@@ -1736,7 +1737,7 @@ bool ScDPOutput::GetHeaderDrag( const ScAddress& rPos, bool bMouseLeft, bool bMo
bool bFound = false; // is this within the same orientation?
bool bBeforeDrag = false;
bool bAfterDrag = false;
- for (long nPos=0; static_cast<size_t>(nPos)<pPageFields.size() && !bFound; nPos++)
+ for (long nPos=0; o3tl::make_unsigned(nPos)<pPageFields.size() && !bFound; nPos++)
{
if (pPageFields[nPos].mnDim == nDragDim)
{
diff --git a/sc/source/core/data/dptabres.cxx b/sc/source/core/data/dptabres.cxx
index b535d5cdc08e..db117a13f638 100644
--- a/sc/source/core/data/dptabres.cxx
+++ b/sc/source/core/data/dptabres.cxx
@@ -32,6 +32,7 @@
#include <dpresfilter.hxx>
#include <dputil.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/math.hxx>
#include <sal/log.hxx>
@@ -819,19 +820,19 @@ long ScDPResultData::GetRowStartMeasure() const
ScSubTotalFunc ScDPResultData::GetMeasureFunction(long nMeasure) const
{
- OSL_ENSURE(static_cast<size_t>(nMeasure) < maMeasureFuncs.size(), "bumm");
+ OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureFuncs.size(), "bumm");
return maMeasureFuncs[nMeasure];
}
const sheet::DataPilotFieldReference& ScDPResultData::GetMeasureRefVal(long nMeasure) const
{
- OSL_ENSURE(static_cast<size_t>(nMeasure) < maMeasureRefs.size(), "bumm");
+ OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureRefs.size(), "bumm");
return maMeasureRefs[nMeasure];
}
sheet::DataPilotFieldOrientation ScDPResultData::GetMeasureRefOrient(long nMeasure) const
{
- OSL_ENSURE(static_cast<size_t>(nMeasure) < maMeasureRefOrients.size(), "bumm");
+ OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureRefOrients.size(), "bumm");
return maMeasureRefOrients[nMeasure];
}
@@ -853,7 +854,7 @@ OUString ScDPResultData::GetMeasureString(long nMeasure, bool bForce, ScSubTotal
}
else
{
- OSL_ENSURE(static_cast<size_t>(nMeasure) < maMeasureFuncs.size(), "bumm");
+ OSL_ENSURE(o3tl::make_unsigned(nMeasure) < maMeasureFuncs.size(), "bumm");
const ScDPDimension* pDataDim = mrSource.GetDataDimension(nMeasure);
if (pDataDim)
{
@@ -3938,7 +3939,7 @@ void ScDPResultVisibilityData::fillFieldFilters(vector<ScDPFilteredCache::Criter
ScDPDimension* pDim = pDims->getByIndex(nDimIndex);
ScDPMembers* pMembers = pDim->GetHierarchiesObject()->getByIndex(0)->
GetLevelsObject()->getByIndex(0)->GetMembersObject();
- if (pGrpFilter->getMatchItemCount() < static_cast<size_t>(pMembers->getCount()))
+ if (pGrpFilter->getMatchItemCount() < o3tl::make_unsigned(pMembers->getCount()))
rFilters.push_back(aCri);
}
}
diff --git a/sc/source/core/data/dptabsrc.cxx b/sc/source/core/data/dptabsrc.cxx
index e8bbd3c91c19..bfc89049a708 100644
--- a/sc/source/core/data/dptabsrc.cxx
+++ b/sc/source/core/data/dptabsrc.cxx
@@ -26,6 +26,7 @@
#include <comphelper/sequence.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/math.hxx>
#include <sal/log.hxx>
@@ -139,7 +140,7 @@ long ScDPSource::GetDataDimensionCount() const
ScDPDimension* ScDPSource::GetDataDimension(long nIndex)
{
- if (nIndex < 0 || static_cast<size_t>(nIndex) >= maDataDims.size())
+ if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maDataDims.size())
return nullptr;
long nDimIndex = maDataDims[nIndex];
@@ -708,7 +709,7 @@ void ScDPSource::FilterCacheByPageDimensions()
pGrpFilter->addMatchItem(aData);
}
}
- if (pGrpFilter->getMatchItemCount() < static_cast<size_t>(nMemCount))
+ if (pGrpFilter->getMatchItemCount() < o3tl::make_unsigned(nMemCount))
// there is at least one invisible item. Add this filter criterion to the mix.
aCriteria.push_back(aFilter);
diff --git a/sc/source/core/data/table1.cxx b/sc/source/core/data/table1.cxx
index 583982ed5f2c..7b6f1f771eb8 100644
--- a/sc/source/core/data/table1.cxx
+++ b/sc/source/core/data/table1.cxx
@@ -19,6 +19,7 @@
#include <scitems.hxx>
#include <editeng/justifyitem.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/textsearch.hxx>
#include <unotools/charclass.hxx>
@@ -167,7 +168,7 @@ bool SetOptimalHeightsToRows(
SCROW nRngEnd = 0;
sal_uInt16 nLast = 0;
sal_uInt16 nExtraHeight = rCxt.getExtraHeight();
- for (SCSIZE i = nStartRow; i <= static_cast<SCSIZE>(nEndRow); i++)
+ for (SCSIZE i = nStartRow; i <= o3tl::make_unsigned(nEndRow); i++)
{
size_t nIndex;
SCROW nRegionEndRow;
diff --git a/sc/source/core/data/table2.cxx b/sc/source/core/data/table2.cxx
index f24a3459a803..cb0aabf72628 100644
--- a/sc/source/core/data/table2.cxx
+++ b/sc/source/core/data/table2.cxx
@@ -56,6 +56,7 @@
#include <scitems.hxx>
#include <editeng/boxitem.hxx>
#include <editeng/editobj.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/poolcach.hxx>
#include <unotools/charclass.hxx>
#include <math.h>
@@ -249,7 +250,7 @@ void ScTable::DeleteRow(
bool ScTable::TestInsertCol( SCROW nStartRow, SCROW nEndRow, SCSIZE nSize ) const
{
- if ( nSize > static_cast<SCSIZE>(pDocument->MaxCol()) )
+ if ( nSize > o3tl::make_unsigned(pDocument->MaxCol()) )
return false;
if ( nStartRow==0 && nEndRow==pDocument->MaxRow() && pOutlineTable
@@ -348,7 +349,7 @@ void ScTable::DeleteCol(
{
if (mpColWidth && mpColFlags)
{
- assert( nStartCol + nSize <= size_t(pDocument->MaxCol()+1) ); // moving 0 if ==pDocument->MaxCol()+1 is correct
+ assert( nStartCol + nSize <= o3tl::make_unsigned(pDocument->MaxCol()+1) ); // moving 0 if ==pDocument->MaxCol()+1 is correct
mpColWidth->RemovePreservingSize(nStartCol, nSize, STD_COL_WIDTH);
mpColFlags->RemovePreservingSize(nStartCol, nSize, CRFlags::NONE);
}
diff --git a/sc/source/core/tool/compiler.cxx b/sc/source/core/tool/compiler.cxx
index 66ce3d569f91..b7e2a1f60f4b 100644
--- a/sc/source/core/tool/compiler.cxx
+++ b/sc/source/core/tool/compiler.cxx
@@ -30,6 +30,7 @@
#include <svl/sharedstringpool.hxx>
#include <sal/macros.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/character.hxx>
#include <tools/solar.h>
@@ -766,7 +767,7 @@ struct ConventionOOO_A1 : public Convention_A1
static void MakeTabStr( OUStringBuffer &rBuf, const std::vector<OUString>& rTabNames, SCTAB nTab )
{
- if (static_cast<size_t>(nTab) >= rTabNames.size())
+ if (o3tl::make_unsigned(nTab) >= rTabNames.size())
rBuf.append(ScResId(STR_NO_REF_TABLE));
else
rBuf.append(rTabNames[nTab]);
@@ -1102,7 +1103,7 @@ struct ConventionXL
const ScSingleRefData& rRef, OUString& rTabName )
{
ScAddress aAbs = rRef.toAbs(rLimits, rPos);
- if (rRef.IsTabDeleted() || static_cast<size_t>(aAbs.Tab()) >= rTabNames.size())
+ if (rRef.IsTabDeleted() || o3tl::make_unsigned(aAbs.Tab()) >= rTabNames.size())
{
rTabName = ScResId( STR_NO_REF_TABLE );
return;
@@ -4507,7 +4508,7 @@ std::unique_ptr<ScTokenArray> ScCompiler::CompileString( const OUString& rFormul
bool bUseFunctionStack = (bPODF || bOOXML);
const size_t nAlloc = 512;
FunctionStack aFuncs[ nAlloc ];
- FunctionStack* pFunctionStack = (bUseFunctionStack && static_cast<size_t>(rFormula.getLength()) > nAlloc ?
+ FunctionStack* pFunctionStack = (bUseFunctionStack && o3tl::make_unsigned(rFormula.getLength()) > nAlloc ?
new FunctionStack[rFormula.getLength()] : &aFuncs[0]);
pFunctionStack[0].eOp = ocNone;
pFunctionStack[0].nSep = 0;
diff --git a/sc/source/core/tool/dbdata.cxx b/sc/source/core/tool/dbdata.cxx
index 8e77f5410dc4..80476b494fa9 100644
--- a/sc/source/core/tool/dbdata.cxx
+++ b/sc/source/core/tool/dbdata.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/transliterationwrapper.hxx>
#include <unotools/charclass.hxx>
@@ -884,7 +885,7 @@ const OUString& ScDBData::GetTableColumnName( SCCOL nCol ) const
return EMPTY_OUSTRING;
SCCOL nOffset = nCol - nStartCol;
- if (nOffset < 0 || maTableColumnNames.size() <= static_cast<size_t>(nOffset))
+ if (nOffset < 0 || maTableColumnNames.size() <= o3tl::make_unsigned(nOffset))
return EMPTY_OUSTRING;
return maTableColumnNames[nOffset];
diff --git a/sc/source/core/tool/grouparealistener.cxx b/sc/source/core/tool/grouparealistener.cxx
index acbace1c4300..fa234fbcc1c1 100644
--- a/sc/source/core/tool/grouparealistener.cxx
+++ b/sc/source/core/tool/grouparealistener.cxx
@@ -18,6 +18,7 @@
#include <document.hxx>
#include <table.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
namespace sc {
@@ -230,7 +231,7 @@ void FormulaGroupAreaListener::collectFormulaCells(
* the content of a shifted column. Effectively this workaround has the
* consequence that the group area listener is fouled up and not all
* formula cells are notified... */
- if (nBlockSize < static_cast<size_t>(mnGroupLen))
+ if (nBlockSize < o3tl::make_unsigned(mnGroupLen))
{
SAL_WARN("sc.core","FormulaGroupAreaListener::collectFormulaCells() nBlockSize " <<
nBlockSize << " < " << mnGroupLen << " mnGroupLen");
diff --git a/sc/source/core/tool/interpr1.cxx b/sc/source/core/tool/interpr1.cxx
index b6fa53b43528..89e7b39786cf 100644
--- a/sc/source/core/tool/interpr1.cxx
+++ b/sc/source/core/tool/interpr1.cxx
@@ -22,6 +22,7 @@
#include <scitems.hxx>
#include <editeng/langitem.hxx>
#include <editeng/justifyitem.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/thread.h>
#include <svx/algitem.hxx>
#include <unotools/textsearch.hxx>
@@ -655,9 +656,9 @@ bool ScInterpreter::JumpMatrix( short nStackLevel )
ScAddress aAdr( aRange.aStart);
sal_uLong nCol = static_cast<sal_uLong>(aAdr.Col()) + nC;
sal_uLong nRow = static_cast<sal_uLong>(aAdr.Row()) + nR;
- if ((nCol > static_cast<sal_uLong>(aRange.aEnd.Col()) &&
+ if ((nCol > o3tl::make_unsigned(aRange.aEnd.Col()) &&
aRange.aEnd.Col() != aRange.aStart.Col())
- || (nRow > static_cast<sal_uLong>(aRange.aEnd.Row()) &&
+ || (nRow > o3tl::make_unsigned(aRange.aEnd.Row()) &&
aRange.aEnd.Row() != aRange.aStart.Row()))
{
fVal = CreateDoubleError( FormulaError::NotAvailable );
@@ -6974,7 +6975,7 @@ void ScInterpreter::ScLookup()
VectorMatrixAccessor aMatAcc(*pDataMat, bVertical);
SCCOLROW i = nDelta;
SCSIZE n = aMatAcc.GetElementCount();
- if (static_cast<SCSIZE>(i) >= n)
+ if (o3tl::make_unsigned(i) >= n)
i = static_cast<SCCOLROW>(n);
bool bByString = rEntry.GetQueryItem().meType == ScQueryEntry::ByString;
if (bByString == aMatAcc.IsValue(i))
@@ -6993,7 +6994,7 @@ void ScInterpreter::ScLookup()
{
VectorMatrixAccessor aResMatAcc(*pResMat, bVertical);
// result array is matrix.
- if (static_cast<SCSIZE>(nDelta) >= aResMatAcc.GetElementCount())
+ if (o3tl::make_unsigned(nDelta) >= aResMatAcc.GetElementCount())
{
PushNA();
return;
@@ -8532,8 +8533,8 @@ void ScInterpreter::ScIndex()
SCSIZE nElement = ::std::max( static_cast<SCSIZE>(nCol),
static_cast<SCSIZE>(nRow));
if (nC == 0 || nR == 0 ||
- (!bVector && (static_cast<SCSIZE>(nCol) > nC ||
- static_cast<SCSIZE>(nRow) > nR)) ||
+ (!bVector && (o3tl::make_unsigned(nCol) > nC ||
+ o3tl::make_unsigned(nRow) > nR)) ||
(bVector && nElement > nC * nR))
PushIllegalArgument();
else if (nCol == 0 && nRow == 0)
diff --git a/sc/source/core/tool/interpr4.cxx b/sc/source/core/tool/interpr4.cxx
index b1a3658961ce..7716a973fd6e 100644
--- a/sc/source/core/tool/interpr4.cxx
+++ b/sc/source/core/tool/interpr4.cxx
@@ -22,6 +22,7 @@
#include <interpre.hxx>
#include <rangelst.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/math.hxx>
#include <sfx2/app.hxx>
#include <sfx2/docfile.hxx>
@@ -1509,9 +1510,9 @@ bool ScInterpreter::ConvertMatrixParameters()
{
if ( eType == formula::ParamClass::Value )
{ // only if single value expected
- if ( nJumpCols < static_cast<SCSIZE>(nCol2 - nCol1 + 1) )
+ if ( nJumpCols < o3tl::make_unsigned(nCol2 - nCol1 + 1) )
nJumpCols = static_cast<SCSIZE>(nCol2 - nCol1 + 1);
- if ( nJumpRows < static_cast<SCSIZE>(nRow2 - nRow1 + 1) )
+ if ( nJumpRows < o3tl::make_unsigned(nRow2 - nRow1 + 1) )
nJumpRows = static_cast<SCSIZE>(nRow2 - nRow1 + 1);
}
formula::FormulaToken* pNew = new ScMatrixToken( pMat);
diff --git a/sc/source/core/tool/token.cxx b/sc/source/core/tool/token.cxx
index 1070fca89e23..99775f5de4b6 100644
--- a/sc/source/core/tool/token.cxx
+++ b/sc/source/core/tool/token.cxx
@@ -61,6 +61,7 @@ using ::std::vector;
#include <com/sun/star/sheet/ReferenceFlags.hpp>
#include <com/sun/star/sheet/NameToken.hpp>
#include <utility>
+#include <o3tl/safeint.hxx>
#include <o3tl/sorted_vector.hxx>
using namespace formula;
@@ -4990,7 +4991,7 @@ void appendTokenByType( ScSheetLimits& rLimits, sc::TokenStringContext& rCxt, OU
{
// On other sheet.
OUString aName;
- if (static_cast<size_t>(nTab) < rCxt.maTabNames.size())
+ if (o3tl::make_unsigned(nTab) < rCxt.maTabNames.size())
aName = rCxt.maTabNames[nTab];
if (!aName.isEmpty())
{
diff --git a/sc/source/filter/excel/excdoc.cxx b/sc/source/filter/excel/excdoc.cxx
index ca21fe210da5..e21164f43632 100644
--- a/sc/source/filter/excel/excdoc.cxx
+++ b/sc/source/filter/excel/excdoc.cxx
@@ -48,6 +48,7 @@
#include <xltools.hxx>
#include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
+#include <o3tl/safeint.hxx>
#include <oox/token/tokens.hxx>
#include <oox/token/namespaces.hxx>
#include <memory>
@@ -410,7 +411,7 @@ void ExcTable::FillAsTableBinary( SCTAB nCodeNameIdx )
ScDocument& rDoc = GetDoc();
OSL_ENSURE( (mnScTab >= 0) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
- OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
+ OSL_ENSURE( nExcTab <= o3tl::make_unsigned(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
// create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
if( eBiff == EXC_BIFF8 )
@@ -552,7 +553,7 @@ void ExcTable::FillAsTableXml()
ScDocument& rDoc = GetDoc();
OSL_ENSURE( (mnScTab >= 0) && (mnScTab <= MAXTAB), "-ExcTable::Table(): mnScTab - no ordinary table!" );
- OSL_ENSURE( nExcTab <= static_cast<sal_uInt16>(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
+ OSL_ENSURE( nExcTab <= o3tl::make_unsigned(MAXTAB), "-ExcTable::Table(): nExcTab - no ordinary table!" );
// create a new OBJ list for this sheet (may be used by notes, autofilter, data validation)
GetObjectManager().StartSheet();
diff --git a/sc/source/filter/excel/excform8.cxx b/sc/source/filter/excel/excform8.cxx
index 4d53dbce4f29..a16dbe60a0f7 100644
--- a/sc/source/filter/excel/excform8.cxx
+++ b/sc/source/filter/excel/excform8.cxx
@@ -31,6 +31,8 @@
#include <cstring>
+#include <o3tl/safeint.hxx>
+
using ::std::vector;
namespace {
@@ -53,7 +55,7 @@ bool extractFilePath(const OUString& rUrl, OUString& rPath)
OUStringBuffer aBuf;
const sal_Unicode* p = rUrl.getStr();
- for (size_t i = 0; i < static_cast<size_t>(n); ++i, ++p)
+ for (size_t i = 0; i < o3tl::make_unsigned(n); ++i, ++p)
{
if (i < nPrefixLen)
{
diff --git a/sc/source/filter/excel/impop.cxx b/sc/source/filter/excel/impop.cxx
index e200dc2aea89..9f94d7b536af 100644
--- a/sc/source/filter/excel/impop.cxx
+++ b/sc/source/filter/excel/impop.cxx
@@ -24,6 +24,7 @@
#include <scitems.hxx>
+#include <o3tl/safeint.hxx>
#include <sfx2/docfile.hxx>
#include <svx/svxids.hrc>
#include <svl/zforlist.hxx>
@@ -246,7 +247,7 @@ void ImportExcel::ReadDimensions()
aXclUsedArea.maFirst.mnCol = maStrm.ReaduInt16();
aXclUsedArea.maLast.mnCol = maStrm.ReaduInt16();
if( (nXclRow1 < nXclRow2) && (aXclUsedArea.GetColCount() > 1) &&
- (nXclRow1 <= static_cast< sal_uInt32 >( GetScMaxPos().Row() )) )
+ (nXclRow1 <= o3tl::make_unsigned( GetScMaxPos().Row() )) )
{
// Excel stores first unused row/column index
--nXclRow2;
diff --git a/sc/source/filter/excel/xeformula.cxx b/sc/source/filter/excel/xeformula.cxx
index f6cf9a2f53b3..9990155ea2e0 100644
--- a/sc/source/filter/excel/xeformula.cxx
+++ b/sc/source/filter/excel/xeformula.cxx
@@ -32,6 +32,7 @@
#include <xestring.hxx>
#include <xllink.hxx>
#include <xltools.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <basegfx/numeric/ftools.hxx>
@@ -197,7 +198,7 @@ void XclExpFuncData::IncParamInfoIdx()
if( mpParamInfo )
{
// move pointer to next entry, if something explicit follows
- if( (static_cast< size_t >( mpParamInfo - mrFuncInfo.mpParamInfos + 1 ) < EXC_FUNCINFO_PARAMINFO_COUNT) && (mpParamInfo[ 1 ].meValid != EXC_PARAM_NONE) )
+ if( (o3tl::make_unsigned( mpParamInfo - mrFuncInfo.mpParamInfos + 1 ) < EXC_FUNCINFO_PARAMINFO_COUNT) && (mpParamInfo[ 1 ].meValid != EXC_PARAM_NONE) )
++mpParamInfo;
// if last parameter type is 'Excel-only' or 'Calc-only', do not repeat it
else if( IsExcelOnlyParam() || IsCalcOnlyParam() )
@@ -2496,7 +2497,7 @@ void XclExpFmlaCompImpl::InsertZeros( sal_uInt16 nInsertPos, sal_uInt16 nInsertS
void XclExpFmlaCompImpl::Overwrite( sal_uInt16 nWriteToPos, sal_uInt16 nOffset )
{
- OSL_ENSURE( static_cast< size_t >( nWriteToPos + 1 ) < mxData->maTokVec.size(), "XclExpFmlaCompImpl::Overwrite - invalid position" );
+ OSL_ENSURE( o3tl::make_unsigned( nWriteToPos + 1 ) < mxData->maTokVec.size(), "XclExpFmlaCompImpl::Overwrite - invalid position" );
ShortToSVBT16( nOffset, &mxData->maTokVec[ nWriteToPos ] );
}
@@ -2513,7 +2514,7 @@ void XclExpFmlaCompImpl::UpdateAttrGoto( sal_uInt16 nAttrPos )
bool XclExpFmlaCompImpl::IsSpaceToken( sal_uInt16 nPos ) const
{
return
- (static_cast< size_t >( nPos + 4 ) <= mxData->maTokVec.size()) &&
+ (o3tl::make_unsigned( nPos + 4 ) <= mxData->maTokVec.size()) &&
(mxData->maTokVec[ nPos ] == EXC_TOKID_ATTR) &&
(mxData->maTokVec[ nPos + 1 ] == EXC_TOK_ATTR_SPACE);
}
diff --git a/sc/source/filter/excel/xepivotxml.cxx b/sc/source/filter/excel/xepivotxml.cxx
index 5d95ffe9c6a1..8bb77f5eb1a0 100644
--- a/sc/source/filter/excel/xepivotxml.cxx
+++ b/sc/source/filter/excel/xepivotxml.cxx
@@ -21,6 +21,7 @@
#include <xeroot.hxx>
#include <o3tl/temporary.hxx>
+#include <o3tl/safeint.hxx>
#include <oox/export/utils.hxx>
#include <oox/token/namespaces.hxx>
#include <sax/tools/converter.hxx>
@@ -58,7 +59,7 @@ void savePivotCacheRecordsXml( XclExpXmlStream& rStrm, const ScDPCache& rCache )
{
const ScDPCache::IndexArrayType* pArray = rCache.GetFieldIndexArray(nField);
assert(pArray);
- assert(static_cast<size_t>(i) < pArray->size());
+ assert(o3tl::make_unsigned(i) < pArray->size());
// We are using XML_x reference (like: <x v="0"/>), instead of values here (eg: <s v="No Discount"/>).
// That's why in SavePivotCacheXml method, we need to list all items.
diff --git a/sc/source/filter/excel/xestring.cxx b/sc/source/filter/excel/xestring.cxx
index 80a89af7a25d..45be12cbbcbf 100644
--- a/sc/source/filter/excel/xestring.cxx
+++ b/sc/source/filter/excel/xestring.cxx
@@ -20,6 +20,7 @@
#include <algorithm>
#include <cassert>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tools/solar.h>
#include <xlstyle.hxx>
@@ -458,7 +459,7 @@ void XclExpString::SetStrLen( sal_Int32 nNewLen )
void XclExpString::CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin, sal_Int32 nLen )
{
- OSL_ENSURE( maUniBuffer.size() >= static_cast< size_t >( nBegin + nLen ),
+ OSL_ENSURE( maUniBuffer.size() >= o3tl::make_unsigned( nBegin + nLen ),
"XclExpString::CharsToBuffer - char buffer invalid" );
ScfUInt16Vec::iterator aBeg = maUniBuffer.begin() + nBegin;
ScfUInt16Vec::iterator aEnd = aBeg + nLen;
@@ -475,7 +476,7 @@ void XclExpString::CharsToBuffer( const sal_Unicode* pcSource, sal_Int32 nBegin,
void XclExpString::CharsToBuffer( const char* pcSource, sal_Int32 nBegin, sal_Int32 nLen )
{
- OSL_ENSURE( maCharBuffer.size() >= static_cast< size_t >( nBegin + nLen ),
+ OSL_ENSURE( maCharBuffer.size() >= o3tl::make_unsigned( nBegin + nLen ),
"XclExpString::CharsToBuffer - char buffer invalid" );
ScfUInt8Vec::iterator aBeg = maCharBuffer.begin() + nBegin;
ScfUInt8Vec::iterator aEnd = aBeg + nLen;
diff --git a/sc/source/filter/excel/xestyle.cxx b/sc/source/filter/excel/xestyle.cxx
index 6bb80bf7dc9d..03a63404d696 100644
--- a/sc/source/filter/excel/xestyle.cxx
+++ b/sc/source/filter/excel/xestyle.cxx
@@ -47,6 +47,7 @@
#include <xltools.hxx>
#include <conditio.hxx>
+#include <o3tl/safeint.hxx>
#include <oox/export/utils.hxx>
#include <oox/token/tokens.hxx>
#include <oox/token/namespaces.hxx>
@@ -1358,7 +1359,7 @@ sal_uInt16 XclExpNumFmtBuffer::Insert( sal_uInt32 nScNumFmt )
return aIt->mnXclNumFmt;
size_t nSize = maFormatMap.size();
- if( nSize < static_cast< size_t >( 0xFFFF - mnXclOffset ) )
+ if( nSize < o3tl::make_unsigned( 0xFFFF - mnXclOffset ) )
{
sal_uInt16 nXclNumFmt = static_cast< sal_uInt16 >( nSize + mnXclOffset );
maFormatMap.emplace_back( nScNumFmt, nXclNumFmt, GetFormatCode( nScNumFmt ) );
diff --git a/sc/source/filter/excel/xiview.cxx b/sc/source/filter/excel/xiview.cxx
index 143512b2bd92..29674e896bc6 100644
--- a/sc/source/filter/excel/xiview.cxx
+++ b/sc/source/filter/excel/xiview.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
+
#include <xiview.hxx>
#include <document.hxx>
#include <scextopt.hxx>
@@ -251,7 +255,7 @@ void XclImpTabViewSettings::Finalize()
#i35812# Excel uses number of visible rows/columns, Calc uses position of freeze. */
if( (maData.mnSplitX > 0) && (maData.maFirstXclPos.mnCol + maData.mnSplitX <= GetScMaxPos().Col()) )
rTabSett.maFreezePos.SetCol( static_cast< SCCOL >( maData.maFirstXclPos.mnCol + maData.mnSplitX ) );
- if( (maData.mnSplitY > 0) && (maData.maFirstXclPos.mnRow + maData.mnSplitY <= static_cast<unsigned>(GetScMaxPos().Row())) )
+ if( (maData.mnSplitY > 0) && (maData.maFirstXclPos.mnRow + maData.mnSplitY <= o3tl::make_unsigned(GetScMaxPos().Row())) )
rTabSett.maFreezePos.SetRow( static_cast< SCROW >( maData.maFirstXclPos.mnRow + maData.mnSplitY ) );
}
else
diff --git a/sc/source/filter/excel/xladdress.cxx b/sc/source/filter/excel/xladdress.cxx
index a11b1959ca64..f897a92a70a3 100644
--- a/sc/source/filter/excel/xladdress.cxx
+++ b/sc/source/filter/excel/xladdress.cxx
@@ -22,6 +22,7 @@
#include <xltracer.hxx>
#include <xistream.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
void XclAddress::Read( XclImpStream& rStrm )
@@ -128,8 +129,8 @@ XclAddressConverterBase::XclAddressConverterBase( XclTracer& rTracer, const ScAd
mbRowTrunc( false ),
mbTabTrunc( false )
{
- OSL_ENSURE( static_cast< size_t >( rMaxPos.Col() ) <= SAL_MAX_UINT16, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
- OSL_ENSURE( static_cast< size_t >( rMaxPos.Row() ) <= SAL_MAX_UINT32, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
+ OSL_ENSURE( o3tl::make_unsigned( rMaxPos.Col() ) <= SAL_MAX_UINT16, "XclAddressConverterBase::XclAddressConverterBase - invalid max column" );
+ OSL_ENSURE( o3tl::make_unsigned( rMaxPos.Row() ) <= SAL_MAX_UINT32, "XclAddressConverterBase::XclAddressConverterBase - invalid max row" );
}
XclAddressConverterBase::~XclAddressConverterBase()
diff --git a/sc/source/filter/oox/externallinkbuffer.cxx b/sc/source/filter/oox/externallinkbuffer.cxx
index 2164c7f71a23..2c6f9d20b78a 100644
--- a/sc/source/filter/oox/externallinkbuffer.cxx
+++ b/sc/source/filter/oox/externallinkbuffer.cxx
@@ -25,6 +25,7 @@
#include <com/sun/star/sheet/XDDELinks.hpp>
#include <com/sun/star/sheet/XDDELinkResults.hpp>
#include <com/sun/star/sheet/XExternalDocLinks.hpp>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <oox/core/filterbase.hxx>
@@ -660,7 +661,7 @@ ExternalLinkRef ExternalLinkBuffer::createExternalLink()
const RefSheetsModel* ExternalLinkBuffer::getRefSheets( sal_Int32 nRefId ) const
{
- return ((0 <= nRefId) && (static_cast< size_t >( nRefId ) < maRefSheets.size())) ?
+ return ((0 <= nRefId) && (o3tl::make_unsigned( nRefId ) < maRefSheets.size())) ?
&maRefSheets[ static_cast< size_t >( nRefId ) ] : nullptr;
}
diff --git a/sc/source/filter/oox/formulabuffer.cxx b/sc/source/filter/oox/formulabuffer.cxx
index 26aec23827db..0d1855468bf1 100644
--- a/sc/source/filter/oox/formulabuffer.cxx
+++ b/sc/source/filter/oox/formulabuffer.cxx
@@ -18,6 +18,7 @@
#include <sharedformulagroups.hxx>
#include <externalrefmgr.hxx>
#include <tokenstringcontext.hxx>
+#include <o3tl/safeint.hxx>
#include <oox/token/tokens.hxx>
#include <oox/helper/progressbar.hxx>
#include <svl/sharedstringpool.hxx>
@@ -399,7 +400,7 @@ FormulaBuffer::SheetItem FormulaBuffer::getSheetItem( SCTAB nTab )
SheetItem aItem;
- if( static_cast<size_t>(nTab) >= maCellFormulas.size() )
+ if( o3tl::make_unsigned(nTab) >= maCellFormulas.size() )
{
SAL_WARN( "sc", "Tab " << nTab << " out of bounds " << maCellFormulas.size() );
return aItem;
@@ -423,7 +424,7 @@ void FormulaBuffer::createSharedFormulaMapEntry(
const ScAddress& rAddress,
sal_Int32 nSharedId, const OUString& rTokens )
{
- assert( rAddress.Tab() >= 0 && static_cast<size_t>(rAddress.Tab()) < maSharedFormulas.size() );
+ assert( rAddress.Tab() >= 0 && o3tl::make_unsigned(rAddress.Tab()) < maSharedFormulas.size() );
std::vector<SharedFormulaEntry>& rSharedFormulas = maSharedFormulas[ rAddress.Tab() ];
SharedFormulaEntry aEntry(rAddress, rTokens, nSharedId);
rSharedFormulas.push_back( aEntry );
@@ -431,14 +432,14 @@ void FormulaBuffer::createSharedFormulaMapEntry(
void FormulaBuffer::setCellFormula( const ScAddress& rAddress, const OUString& rTokenStr )
{
- assert( rAddress.Tab() >= 0 && static_cast<size_t>(rAddress.Tab()) < maCellFormulas.size() );
+ assert( rAddress.Tab() >= 0 && o3tl::make_unsigned(rAddress.Tab()) < maCellFormulas.size() );
maCellFormulas[ rAddress.Tab() ].emplace_back( rTokenStr, rAddress );
}
void FormulaBuffer::setCellFormula(
const ScAddress& rAddress, sal_Int32 nSharedId, const OUString& rCellValue, sal_Int32 nValueType )
{
- assert( rAddress.Tab() >= 0 && static_cast<size_t>(rAddress.Tab()) < maSharedFormulaIds.size() );
+ assert( rAddress.Tab() >= 0 && o3tl::make_unsigned(rAddress.Tab()) < maSharedFormulaIds.size() );
maSharedFormulaIds[rAddress.Tab()].emplace_back(rAddress, nSharedId, rCellValue, nValueType);
}
@@ -446,14 +447,14 @@ void FormulaBuffer::setCellArrayFormula( const ScRange& rRangeAddress, const ScA
{
TokenAddressItem tokenPair( rTokenStr, rTokenAddress );
- assert( rRangeAddress.aStart.Tab() >= 0 && static_cast<size_t>(rRangeAddress.aStart.Tab()) < maCellArrayFormulas.size() );
+ assert( rRangeAddress.aStart.Tab() >= 0 && o3tl::make_unsigned(rRangeAddress.aStart.Tab()) < maCellArrayFormulas.size() );
maCellArrayFormulas[ rRangeAddress.aStart.Tab() ].emplace_back( tokenPair, rRangeAddress );
}
void FormulaBuffer::setCellFormulaValue(
const ScAddress& rAddress, const OUString& rValueStr, sal_Int32 nCellType )
{
- assert( rAddress.Tab() >= 0 && static_cast<size_t>(rAddress.Tab()) < maCellFormulaValues.size() );
+ assert( rAddress.Tab() >= 0 && o3tl::make_unsigned(rAddress.Tab()) < maCellFormulaValues.size() );
FormulaValue aVal;
aVal.maAddress = rAddress;
aVal.maValueStr = rValueStr;
diff --git a/sc/source/filter/oox/pivotcachebuffer.cxx b/sc/source/filter/oox/pivotcachebuffer.cxx
index a2e5d8d66360..e80605b9c130 100644
--- a/sc/source/filter/oox/pivotcachebuffer.cxx
+++ b/sc/source/filter/oox/pivotcachebuffer.cxx
@@ -26,6 +26,7 @@
#include <com/sun/star/sheet/DataPilotFieldGroupBy.hpp>
#include <com/sun/star/sheet/DataPilotFieldGroupInfo.hpp>
#include <com/sun/star/sheet/XDataPilotFieldGrouping.hpp>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <sal/log.hxx>
#include <oox/helper/attributelist.hxx>
@@ -305,7 +306,7 @@ void PivotCacheItemList::applyItemCaptions( const IdCaptionPairList& vCaptions )
{
for( const auto& [rId, rCaption] : vCaptions )
{
- if ( static_cast<sal_uInt32>( rId ) < maItems.size() )
+ if ( o3tl::make_unsigned( rId ) < maItems.size() )
maItems[ rId ].setStringValue( rCaption );
}
}
diff --git a/sc/source/filter/xml/XMLStylesExportHelper.cxx b/sc/source/filter/xml/XMLStylesExportHelper.cxx
index 5c3b9b5163f1..f5a374529b8b 100644
--- a/sc/source/filter/xml/XMLStylesExportHelper.cxx
+++ b/sc/source/filter/xml/XMLStylesExportHelper.cxx
@@ -34,6 +34,7 @@
#include <comphelper/extract.hxx>
#include <comphelper/propertysequence.hxx>
#include <sfx2/app.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
using namespace com::sun::star;
@@ -423,7 +424,7 @@ void ScMyValidationsContainer::WriteValidations(ScXMLExport& rExport)
const OUString& ScMyValidationsContainer::GetValidationName(const sal_Int32 nIndex)
{
- OSL_ENSURE( static_cast<size_t>(nIndex) < aValidationVec.size(), "out of range" );
+ OSL_ENSURE( o3tl::make_unsigned(nIndex) < aValidationVec.size(), "out of range" );
return aValidationVec[nIndex].sName;
}
@@ -728,7 +729,7 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
sal_Int32 nPrefixLength(rPrefix.getLength());
OUString sTemp(rString.copy(nPrefixLength));
sal_Int32 nIndex(sTemp.toInt32());
- if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1) == rString)
+ if (nIndex > 0 && o3tl::make_unsigned(nIndex-1) < aAutoStyleNames.size() && aAutoStyleNames.at(nIndex - 1) == rString)
{
bIsAutoStyle = true;
return nIndex - 1;
@@ -737,7 +738,7 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
{
sal_Int32 i(0);
bool bFound(false);
- while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
+ while (!bFound && o3tl::make_unsigned(i) < aStyleNames.size())
{
if (aStyleNames[i] == rString)
bFound = true;
@@ -752,7 +753,7 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
else
{
i = 0;
- while (!bFound && static_cast<size_t>(i) < aAutoStyleNames.size())
+ while (!bFound && o3tl::make_unsigned(i) < aAutoStyleNames.size())
{
if (aAutoStyleNames[i] == rString)
bFound = true;
@@ -773,8 +774,8 @@ sal_Int32 ScFormatRangeStyles::GetIndexOfStyleName(const OUString& rString, cons
sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
const sal_Int32 nColumn, const sal_Int32 nRow, bool& bIsAutoStyle) const
{
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
- if (static_cast<size_t>(nTable) >= aTables.size())
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
+ if (o3tl::make_unsigned(nTable) >= aTables.size())
return -1;
for (const ScMyFormatRange & rFormatRange : aTables[nTable])
{
@@ -793,8 +794,8 @@ sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable,
sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nColumn, const sal_Int32 nRow,
bool& bIsAutoStyle, sal_Int32& nValidationIndex, sal_Int32& nNumberFormat, const sal_Int32 nRemoveBeforeRow)
{
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
- if (static_cast<size_t>(nTable) >= aTables.size())
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
+ if (o3tl::make_unsigned(nTable) >= aTables.size())
return -1;
ScMyFormatRangeAddresses& rFormatRanges(aTables[nTable]);
ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
@@ -809,8 +810,8 @@ sal_Int32 ScFormatRangeStyles::GetStyleNameIndex(const sal_Int32 nTable, const s
bIsAutoStyle = aItr->bIsAutoStyle;
nValidationIndex = aItr->nValidationIndex;
nNumberFormat = aItr->nNumberFormat;
- OSL_ENSURE( static_cast<size_t>(nColumn) < pColDefaults->size(), "nColumn out of bounds");
- if (static_cast<size_t>(nColumn) < pColDefaults->size() &&
+ OSL_ENSURE( o3tl::make_unsigned(nColumn) < pColDefaults->size(), "nColumn out of bounds");
+ if (o3tl::make_unsigned(nColumn) < pColDefaults->size() &&
((*pColDefaults)[nColumn].nIndex != -1) &&
((*pColDefaults)[nColumn].nIndex == (*aItr).nStyleNameIndex) &&
((*pColDefaults)[nColumn].bIsAutoStyle == (*aItr).bIsAutoStyle))
@@ -833,7 +834,7 @@ void ScFormatRangeStyles::GetFormatRanges(const sal_Int32 nStartColumn, const sa
const sal_Int32 nTable, ScRowFormatRanges* pRowFormatRanges)
{
sal_Int32 nTotalColumns(nEndColumn - nStartColumn + 1);
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
ScMyFormatRangeAddresses& rFormatRanges(aTables[nTable]);
ScMyFormatRangeAddresses::iterator aItr(rFormatRanges.begin());
ScMyFormatRangeAddresses::iterator aEndItr(rFormatRanges.end());
@@ -901,7 +902,7 @@ void ScFormatRangeStyles::AddRangeStyleName(const table::CellRangeAddress& rCell
aFormatRange.nValidationIndex = nValidationIndex;
aFormatRange.nNumberFormat = nNumberFormat;
aFormatRange.bIsAutoStyle = bIsAutoStyle;
- OSL_ENSURE(static_cast<size_t>(rCellRangeAddress.Sheet) < aTables.size(), "wrong table");
+ OSL_ENSURE(o3tl::make_unsigned(rCellRangeAddress.Sheet) < aTables.size(), "wrong table");
ScMyFormatRangeAddresses& rFormatRanges(aTables[rCellRangeAddress.Sheet]);
rFormatRanges.push_back(aFormatRange);
}
@@ -940,13 +941,13 @@ sal_Int32 ScColumnRowStylesBase::GetIndexOfStyleName(const OUString& rString, co
sal_Int32 nPrefixLength(rPrefix.getLength());
OUString sTemp(rString.copy(nPrefixLength));
sal_Int32 nIndex(sTemp.toInt32());
- if (nIndex > 0 && static_cast<size_t>(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1) == rString)
+ if (nIndex > 0 && o3tl::make_unsigned(nIndex-1) < aStyleNames.size() && aStyleNames.at(nIndex - 1) == rString)
return nIndex - 1;
else
{
sal_Int32 i(0);
bool bFound(false);
- while (!bFound && static_cast<size_t>(i) < aStyleNames.size())
+ while (!bFound && o3tl::make_unsigned(i) < aStyleNames.size())
{
if (aStyleNames.at(i) == rString)
bFound = true;
@@ -989,8 +990,8 @@ void ScColumnStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields
sal_Int32 ScColumnStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField,
bool& bIsVisible)
{
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
- if (static_cast<size_t>(nField) < aTables[nTable].size())
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
+ if (o3tl::make_unsigned(nField) < aTables[nTable].size())
{
bIsVisible = aTables[nTable][nField].bIsVisible;
return aTables[nTable][nField].nIndex;
@@ -1005,8 +1006,8 @@ sal_Int32 ScColumnStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_In
void ScColumnStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
const sal_Int32 nStringIndex, const bool bIsVisible)
{
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
- OSL_ENSURE(aTables[nTable].size() >= static_cast<sal_uInt32>(nField), "wrong field");
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
+ OSL_ENSURE(aTables[nTable].size() >= o3tl::make_unsigned(nField), "wrong field");
ScColumnStyle aStyle;
aStyle.nIndex = nStringIndex;
aStyle.bIsVisible = bIsVisible;
@@ -1044,8 +1045,8 @@ void ScRowStyles::AddNewTable(const sal_Int32 nTable, const sal_Int32 nFields)
sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32 nField)
{
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
- if (static_cast<size_t>(nTable) >= aTables.size())
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
+ if (o3tl::make_unsigned(nTable) >= aTables.size())
return -1;
if (maCache.hasCache(nTable, nField))
@@ -1073,7 +1074,7 @@ sal_Int32 ScRowStyles::GetStyleNameIndex(const sal_Int32 nTable, const sal_Int32
void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nField,
const sal_Int32 nStringIndex)
{
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
StylesType& r = *aTables[nTable];
r.insert_back(nField, nField+1, nStringIndex);
}
@@ -1082,7 +1083,7 @@ void ScRowStyles::AddFieldStyleName(const sal_Int32 nTable, const sal_Int32 nSta
const sal_Int32 nStringIndex, const sal_Int32 nEndField)
{
OSL_ENSURE( nStartField <= nEndField, "bad field range");
- OSL_ENSURE(static_cast<size_t>(nTable) < aTables.size(), "wrong table");
+ OSL_ENSURE(o3tl::make_unsigned(nTable) < aTables.size(), "wrong table");
StylesType& r = *aTables[nTable];
r.insert_back(nStartField, nEndField+1, nStringIndex);
}
diff --git a/sc/source/ui/Accessibility/AccessibleDocument.cxx b/sc/source/ui/Accessibility/AccessibleDocument.cxx
index a9da52b3d073..22bdd25ea433 100644
--- a/sc/source/ui/Accessibility/AccessibleDocument.cxx
+++ b/sc/source/ui/Accessibility/AccessibleDocument.cxx
@@ -42,7 +42,7 @@
#include <com/sun/star/drawing/XShape.hpp>
#include <com/sun/star/drawing/XShapes.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
-
+#include <o3tl/safeint.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <tools/gen.hxx>
#include <svx/svdpage.hxx>
@@ -550,7 +550,7 @@ uno::Reference< XAccessible > ScChildrenShapes::Get(sal_Int32 nIndex) const
mbShapesNeedSorting = false;
}
- if (static_cast<sal_uInt32>(nIndex) >= maZOrderedShapes.size())
+ if (o3tl::make_unsigned(nIndex) >= maZOrderedShapes.size())
return nullptr;
return Get(maZOrderedShapes[nIndex]);
@@ -810,7 +810,7 @@ uno::Reference< XAccessible > ScChildrenShapes::GetSelected(sal_Int32 nSelectedC
std::vector < uno::Reference < drawing::XShape > > aShapes;
FillShapes(aShapes);
- if (nSelectedChildIndex < 0 || static_cast<size_t>(nSelectedChildIndex) >= aShapes.size())
+ if (nSelectedChildIndex < 0 || o3tl::make_unsigned(nSelectedChildIndex) >= aShapes.size())
return xAccessible;
SortedShapes::iterator aItr;
diff --git a/sc/source/ui/Accessibility/AccessibleFilterMenu.cxx b/sc/source/ui/Accessibility/AccessibleFilterMenu.cxx
index 7dfcae0e7edf..70202f93170f 100644
--- a/sc/source/ui/Accessibility/AccessibleFilterMenu.cxx
+++ b/sc/source/ui/Accessibility/AccessibleFilterMenu.cxx
@@ -21,6 +21,7 @@
#include <AccessibleFilterMenu.hxx>
#include <AccessibleFilterMenuItem.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/gen.hxx>
#include <checklistmenu.hxx>
@@ -116,7 +117,7 @@ sal_Int32 ScAccessibleFilterMenu::getAccessibleChildCount()
Reference<XAccessible> ScAccessibleFilterMenu::getAccessibleChild(sal_Int32 nIndex)
{
- if (maMenuItems.size() <= static_cast<size_t>(nIndex))
+ if (maMenuItems.size() <= o3tl::make_unsigned(nIndex))
throw IndexOutOfBoundsException();
return maMenuItems[nIndex];
@@ -153,7 +154,7 @@ void ScAccessibleFilterMenu::removeAccessibleEventListener(
void ScAccessibleFilterMenu::selectAccessibleChild(sal_Int32 nChildIndex)
{
- if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
+ if (o3tl::make_unsigned(nChildIndex) >= maMenuItems.size())
throw IndexOutOfBoundsException();
mpWindow->setSelectedMenuItem(nChildIndex, false, true);
@@ -161,7 +162,7 @@ void ScAccessibleFilterMenu::selectAccessibleChild(sal_Int32 nChildIndex)
sal_Bool ScAccessibleFilterMenu::isAccessibleChildSelected(sal_Int32 nChildIndex)
{
- if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
+ if (o3tl::make_unsigned(nChildIndex) >= maMenuItems.size())
throw IndexOutOfBoundsException();
return mpWindow->isMenuItemSelected(static_cast<size_t>(nChildIndex));
@@ -185,7 +186,7 @@ sal_Int32 ScAccessibleFilterMenu::getSelectedAccessibleChildCount()
Reference<XAccessible> ScAccessibleFilterMenu::getSelectedAccessibleChild(sal_Int32 nChildIndex)
{
- if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
+ if (o3tl::make_unsigned(nChildIndex) >= maMenuItems.size())
throw IndexOutOfBoundsException();
return maMenuItems[nChildIndex];
@@ -193,7 +194,7 @@ Reference<XAccessible> ScAccessibleFilterMenu::getSelectedAccessibleChild(sal_In
void ScAccessibleFilterMenu::deselectAccessibleChild(sal_Int32 nChildIndex)
{
- if (static_cast<size_t>(nChildIndex) >= maMenuItems.size())
+ if (o3tl::make_unsigned(nChildIndex) >= maMenuItems.size())
throw IndexOutOfBoundsException();
mpWindow->selectMenuItem(nChildIndex, false, false);
diff --git a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
index a25f33658367..b2c743b8234b 100644
--- a/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
+++ b/sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx
@@ -27,6 +27,7 @@
#include <markdata.hxx>
#include <gridwin.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <unotools/accessiblerelationsethelper.hxx>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
@@ -200,7 +201,7 @@ bool ScAccessibleSpreadsheet::CalcScRangeListDifferenceMax(ScRangeList *pSrc, Sc
int nSize =0;
if (pDest->GetCellCount() == 0)//if the Dest Rang List is empty
{
- if (pSrc->GetCellCount() > sal_uInt32(nMax))//if the Src Cell count is greater than nMax
+ if (pSrc->GetCellCount() > o3tl::make_unsigned(nMax))//if the Src Cell count is greater than nMax
{
return true;
}
@@ -1144,7 +1145,7 @@ uno::Reference<XAccessible > SAL_CALL
if (mpMarkedRanges)
{
if ((nSelectedChildIndex < 0) ||
- (mpMarkedRanges->GetCellCount() <= static_cast<sal_uInt32>(nSelectedChildIndex)))
+ (mpMarkedRanges->GetCellCount() <= o3tl::make_unsigned(nSelectedChildIndex)))
{
throw lang::IndexOutOfBoundsException();
}
diff --git a/sc/source/ui/condformat/condformathelper.cxx b/sc/source/ui/condformat/condformathelper.cxx
index dc40f5464803..130785249469 100644
--- a/sc/source/ui/condformat/condformathelper.cxx
+++ b/sc/source/ui/condformat/condformathelper.cxx
@@ -7,6 +7,9 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <condformathelper.hxx>
#include <globstr.hrc>
@@ -117,7 +120,7 @@ OUString getDateString(sal_Int32 nIndex)
STR_COND_NEXTYEAR
};
- if (nIndex >= 0 && static_cast<sal_uInt32>(nIndex) < SAL_N_ELEMENTS(aCondStrs))
+ if (nIndex >= 0 && o3tl::make_unsigned(nIndex) < SAL_N_ELEMENTS(aCondStrs))
return ScResId(aCondStrs[nIndex]);
assert(false);
return OUString();
diff --git a/sc/source/ui/dbgui/consdlg.cxx b/sc/source/ui/dbgui/consdlg.cxx
index 4892cf044377..db55aaa0c657 100644
--- a/sc/source/ui/dbgui/consdlg.cxx
+++ b/sc/source/ui/dbgui/consdlg.cxx
@@ -32,6 +32,7 @@
#include <strings.hrc>
#include <consdlg.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <vcl/weld.hxx>
@@ -452,7 +453,7 @@ IMPL_LINK( ScConsolidateDlg, SelectCBHdl, weld::ComboBox&, rLb, void )
&& (nAreaDataCount > 0)
&& (pAreaData != nullptr) )
{
- if ( static_cast<size_t>(nSelPos) <= nAreaDataCount )
+ if ( o3tl::make_unsigned(nSelPos) <= nAreaDataCount )
{
OUString aString( pAreaData[nSelPos-1].aStrArea );
diff --git a/sc/source/ui/docshell/docfunc.cxx b/sc/source/ui/docshell/docfunc.cxx
index b65edc73a8c0..ae76b44f9551 100644
--- a/sc/source/ui/docshell/docfunc.cxx
+++ b/sc/source/ui/docshell/docfunc.cxx
@@ -20,6 +20,7 @@
#include <scitems.hxx>
#include <comphelper/lok.hxx>
+#include <o3tl/safeint.hxx>
#include <sfx2/app.hxx>
#include <editeng/editobj.hxx>
#include <editeng/justifyitem.hxx>
@@ -1028,7 +1029,7 @@ bool ScDocFunc::SetFormulaCells( const ScAddress& rPos, std::vector<ScFormulaCel
ScDocument& rDoc = rDocShell.GetDocument();
const size_t nLength = rCells.size();
- if (rPos.Row() + nLength - 1 > static_cast<size_t>(rDoc.MaxRow()))
+ if (rPos.Row() + nLength - 1 > o3tl::make_unsigned(rDoc.MaxRow()))
// out of bound
return false;
diff --git a/sc/source/ui/docshell/externalrefmgr.cxx b/sc/source/ui/docshell/externalrefmgr.cxx
index b06fefbf687d..f16f0f70b066 100644
--- a/sc/source/ui/docshell/externalrefmgr.cxx
+++ b/sc/source/ui/docshell/externalrefmgr.cxx
@@ -36,6 +36,7 @@
#include <defaultsoptions.hxx>
#include <scmod.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <sfx2/app.hxx>
#include <sfx2/docfile.hxx>
@@ -636,8 +637,8 @@ ScExternalRefCache::TokenArrayRef ScExternalRefCache::getCellRangeData(
}
}
- if (nMinCol <= nMaxCol && ((static_cast<SCSIZE>(nMaxCol-nMinCol+1) < nMatrixColumns) ||
- (static_cast<SCSIZE>(nDataRow2-nDataRow1+1) < nMatrixRows)))
+ if (nMinCol <= nMaxCol && ((o3tl::make_unsigned(nMaxCol-nMinCol+1) < nMatrixColumns) ||
+ (o3tl::make_unsigned(nDataRow2-nDataRow1+1) < nMatrixRows)))
{
nMatrixColumns = static_cast<SCSIZE>(nMaxCol-nMinCol+1);
nMatrixRows = static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
@@ -825,7 +826,7 @@ void ScExternalRefCache::setCellRangeData(sal_uInt16 nFileId, const ScRange& rRa
const ScMatrixRef& pMat = rItem.mpRangeData;
SCSIZE nMatCols, nMatRows;
pMat->GetDimensions( nMatCols, nMatRows);
- if (nMatCols > static_cast<SCSIZE>(nCol2 - nCol1) && nMatRows > static_cast<SCSIZE>(nRow2 - nRow1))
+ if (nMatCols > o3tl::make_unsigned(nCol2 - nCol1) && nMatRows > o3tl::make_unsigned(nRow2 - nRow1))
{
ScMatrix::DoubleOpFunction aDoubleFunc = [=](size_t row, size_t col, double val) -> void
{
@@ -1577,8 +1578,8 @@ static std::unique_ptr<ScTokenArray> convertToTokenArray(
}
else if ((nCol1 == 0 && nCol2 == MAXCOL) || (nRow1 == 0 && nRow2 == MAXROW))
{
- if ((static_cast<SCSIZE>(nDataCol2-nDataCol1+1) < nMatrixColumns) ||
- (static_cast<SCSIZE>(nDataRow2-nDataRow1+1) < nMatrixRows))
+ if ((o3tl::make_unsigned(nDataCol2-nDataCol1+1) < nMatrixColumns) ||
+ (o3tl::make_unsigned(nDataRow2-nDataRow1+1) < nMatrixRows))
{
nMatrixColumns = static_cast<SCSIZE>(nDataCol2-nDataCol1+1);
nMatrixRows = static_cast<SCSIZE>(nDataRow2-nDataRow1+1);
diff --git a/sc/source/ui/unoobj/PivotTableDataProvider.cxx b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
index d7979cda8cbe..859ef12208cb 100644
--- a/sc/source/ui/unoobj/PivotTableDataProvider.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataProvider.cxx
@@ -23,6 +23,7 @@
#include <dpobject.hxx>
#include <hints.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <sfx2/objsh.hxx>
#include <comphelper/propertysequence.hxx>
@@ -410,7 +411,7 @@ void PivotTableDataProvider::collectPivotTableData()
if (i >= m_aLabels.size())
m_aLabels.resize(i + 1);
- if (size_t(nDimPos) >= m_aLabels[i].size())
+ if (o3tl::make_unsigned(nDimPos) >= m_aLabels[i].size())
m_aLabels[i].resize(nDimPos + 1);
m_aLabels[i][nDimPos] = ValueAndFormat(sCaption);
@@ -459,11 +460,11 @@ void PivotTableDataProvider::collectPivotTableData()
if (i >= m_aCategoriesRowOrientation.size())
m_aCategoriesRowOrientation.resize(i + 1);
- if (size_t(nDimPos) >= m_aCategoriesColumnOrientation.size())
+ if (o3tl::make_unsigned(nDimPos) >= m_aCategoriesColumnOrientation.size())
m_aCategoriesColumnOrientation.resize(nDimPos + 1);
m_aCategoriesColumnOrientation[nDimPos].push_back(*pItem);
- if (size_t(nDimPos) >= m_aCategoriesRowOrientation[i].size())
+ if (o3tl::make_unsigned(nDimPos) >= m_aCategoriesRowOrientation[i].size())
m_aCategoriesRowOrientation[i].resize(nDimPos + 1);
m_aCategoriesRowOrientation[i][nDimPos] = *pItem;
diff --git a/sc/source/ui/unoobj/PivotTableDataSequence.cxx b/sc/source/ui/unoobj/PivotTableDataSequence.cxx
index 706cedd3e025..ad198c190452 100644
--- a/sc/source/ui/unoobj/PivotTableDataSequence.cxx
+++ b/sc/source/ui/unoobj/PivotTableDataSequence.cxx
@@ -12,7 +12,7 @@
#include <sal/config.h>
#include <sal/log.hxx>
-
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <vcl/svapp.hxx>
@@ -152,7 +152,7 @@ sal_Int32 SAL_CALL PivotTableDataSequence::getNumberFormatKeyByIndex(sal_Int32 n
{
return m_aData[0].m_nNumberFormat;
}
- else if (nIndex < 0 && size_t(nIndex) >= m_aData.size())
+ else if (nIndex < 0 && o3tl::make_unsigned(nIndex) >= m_aData.size())
{
SAL_WARN("sc.ui", "Passed invalid index to getNumberFormatKeyByIndex(). Will return default value '0'.");
return 0;
diff --git a/sc/source/ui/unoobj/cellsuno.cxx b/sc/source/ui/unoobj/cellsuno.cxx
index dc1cd9c1e754..89cd63a9144d 100644
--- a/sc/source/ui/unoobj/cellsuno.cxx
+++ b/sc/source/ui/unoobj/cellsuno.cxx
@@ -19,6 +19,7 @@
#include <scitems.hxx>
#include <editeng/eeitem.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/svdpool.hxx>
#include <vcl/svapp.hxx>
@@ -9286,7 +9287,7 @@ uno::Any SAL_CALL ScUniqueCellFormatsObj::getByIndex( sal_Int32 nIndex )
{
SolarMutexGuard aGuard;
- if(static_cast<sal_uInt32>(nIndex) >= aRangeLists.size())
+ if(o3tl::make_unsigned(nIndex) >= aRangeLists.size())
throw lang::IndexOutOfBoundsException();
return uno::makeAny(uno::Reference<sheet::XSheetCellRangeContainer>(new ScCellRangesObj(pDocShell, aRangeLists[nIndex])));
@@ -9349,7 +9350,7 @@ void ScUniqueCellFormatsEnumeration::Notify( SfxBroadcaster&, const SfxHint& rHi
sal_Bool SAL_CALL ScUniqueCellFormatsEnumeration::hasMoreElements()
{
SolarMutexGuard aGuard;
- return static_cast<sal_uInt32>(nCurrentPosition) < aRangeLists.size();
+ return o3tl::make_unsigned(nCurrentPosition) < aRangeLists.size();
}
uno::Any SAL_CALL ScUniqueCellFormatsEnumeration::nextElement()
diff --git a/sc/source/ui/unoobj/chart2uno.cxx b/sc/source/ui/unoobj/chart2uno.cxx
index ab8ae531690e..b1cbba83bb77 100644
--- a/sc/source/ui/unoobj/chart2uno.cxx
+++ b/sc/source/ui/unoobj/chart2uno.cxx
@@ -44,6 +44,7 @@
#include <brdcst.hxx>
#include <formula/opcode.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/sharedstring.hxx>
#include <sfx2/objsh.hxx>
@@ -164,7 +165,7 @@ struct TokenTable
void push_back( std::unique_ptr<FormulaToken> pToken )
{
maTokens.push_back( std::move(pToken) );
- OSL_ENSURE( maTokens.size()<= static_cast<sal_uInt32>( mnColCount*mnRowCount ), "too many tokens" );
+ OSL_ENSURE( maTokens.size()<= o3tl::make_unsigned( mnColCount*mnRowCount ), "too many tokens" );
}
sal_uInt32 getIndex(SCCOL nCol, SCROW nRow) const
@@ -172,7 +173,7 @@ struct TokenTable
OSL_ENSURE( nCol<mnColCount, "wrong column index" );
OSL_ENSURE( nRow<mnRowCount, "wrong row index" );
sal_uInt32 nRet = static_cast<sal_uInt32>(nCol*mnRowCount + nRow);
- OSL_ENSURE( maTokens.size()>= static_cast<sal_uInt32>( mnColCount*mnRowCount ), "too few tokens" );
+ OSL_ENSURE( maTokens.size()>= o3tl::make_unsigned( mnColCount*mnRowCount ), "too few tokens" );
return nRet;
}
diff --git a/sc/source/ui/unoobj/condformatuno.cxx b/sc/source/ui/unoobj/condformatuno.cxx
index 038064c87cc3..692e3a9591a6 100644
--- a/sc/source/ui/unoobj/condformatuno.cxx
+++ b/sc/source/ui/unoobj/condformatuno.cxx
@@ -20,6 +20,7 @@
#include <cellsuno.hxx>
#include <convuno.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
@@ -509,7 +510,7 @@ void ScCondFormatObj::createEntry(const sal_Int32 nType, const sal_Int32 nPos)
void ScCondFormatObj::removeByIndex(const sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
- if (getCoreObject()->size() >= size_t(nIndex))
+ if (getCoreObject()->size() >= o3tl::make_unsigned(nIndex))
throw lang::IllegalArgumentException();
getCoreObject()->RemoveEntry(nIndex);
@@ -538,7 +539,7 @@ sal_Int32 ScCondFormatObj::getCount()
uno::Any ScCondFormatObj::getByIndex(sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
- if (getCoreObject()->size() <= size_t(nIndex))
+ if (getCoreObject()->size() <= o3tl::make_unsigned(nIndex))
throw lang::IllegalArgumentException();
const ScFormatEntry* pEntry = getCoreObject()->GetEntry(nIndex);
@@ -1587,7 +1588,7 @@ void SAL_CALL ScIconSetFormatObj::setPropertyValue(
// TODO: we need to check that the number of entries
// corresponds to the icon type
sal_Int32 nLength = aEntries.getLength();
- for (size_t i = 0; i < size_t(nLength); ++i)
+ for (size_t i = 0; i < o3tl::make_unsigned(nLength); ++i)
{
setIconSetEntry(getCoreObject(), aEntries[i], i);
}
diff --git a/sc/source/ui/unoobj/docuno.cxx b/sc/source/ui/unoobj/docuno.cxx
index 347102005723..a79540c7a20b 100644
--- a/sc/source/ui/unoobj/docuno.cxx
+++ b/sc/source/ui/unoobj/docuno.cxx
@@ -26,6 +26,7 @@
#include <editeng/editview.hxx>
#include <editeng/outliner.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/fmview.hxx>
#include <svx/svditer.hxx>
#include <svx/svdpage.hxx>
@@ -3242,10 +3243,10 @@ void ScModelObj::selectOpenCLDevice( sal_Int32 nPlatform, sal_Int32 nDevice )
#else
std::vector<OpenCLPlatformInfo> aPlatformInfo;
sc::FormulaGroupInterpreter::fillOpenCLInfo(aPlatformInfo);
- if(size_t(nPlatform) >= aPlatformInfo.size())
+ if(o3tl::make_unsigned(nPlatform) >= aPlatformInfo.size())
throw uno::RuntimeException();
- if(size_t(nDevice) >= aPlatformInfo[nPlatform].maDevices.size())
+ if(o3tl::make_unsigned(nDevice) >= aPlatformInfo[nPlatform].maDevices.size())
throw uno::RuntimeException();
OUString aDeviceString = aPlatformInfo[nPlatform].maVendor + " " + aPlatformInfo[nPlatform].maDevices[nDevice].maName;
diff --git a/sc/source/ui/vba/vbawindow.cxx b/sc/source/ui/vba/vbawindow.cxx
index 34e2e95d54b3..d7dda7c89f0d 100644
--- a/sc/source/ui/vba/vbawindow.cxx
+++ b/sc/source/ui/vba/vbawindow.cxx
@@ -31,6 +31,7 @@
#include <com/sun/star/container/XNamed.hpp>
#include <com/sun/star/view/DocumentZoomType.hpp>
#include <com/sun/star/table/CellRangeAddress.hpp>
+#include <o3tl/safeint.hxx>
#include <ooo/vba/excel/XApplication.hpp>
#include <ooo/vba/excel/XlWindowState.hpp>
#include <ooo/vba/excel/XlWindowView.hpp>
@@ -144,7 +145,7 @@ public:
virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
{
if ( Index < 0
- || static_cast< Sheets::size_type >( Index ) >= sheets.size() )
+ || o3tl::make_unsigned( Index ) >= sheets.size() )
throw lang::IndexOutOfBoundsException();
return uno::makeAny( sheets[ Index ] );
diff --git a/sc/source/ui/vba/vbawindows.cxx b/sc/source/ui/vba/vbawindows.cxx
index b9b869f60412..26f621eb2330 100644
--- a/sc/source/ui/vba/vbawindows.cxx
+++ b/sc/source/ui/vba/vbawindows.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/frame/Desktop.hpp>
#include <cppuhelper/implbase.hxx>
#include <comphelper/sequence.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ref.hxx>
#include "vbawindow.hxx"
@@ -160,7 +161,7 @@ public:
virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
{
if ( Index < 0
- || static_cast< Components::size_type >( Index ) >= m_windows.size() )
+ || o3tl::make_unsigned( Index ) >= m_windows.size() )
throw lang::IndexOutOfBoundsException();
return makeAny( m_windows[ Index ] ); // returns xspreadsheetdoc
}
diff --git a/sc/source/ui/view/viewdata.cxx b/sc/source/ui/view/viewdata.cxx
index b719605dde56..cef40898bce6 100644
--- a/sc/source/ui/view/viewdata.cxx
+++ b/sc/source/ui/view/viewdata.cxx
@@ -19,7 +19,7 @@
#include <scitems.hxx>
#include <editeng/eeitem.hxx>
-
+#include <o3tl/safeint.hxx>
#include <sfx2/lokhelper.hxx>
#include <sfx2/viewfrm.hxx>
#include <editeng/adjustitem.hxx>
@@ -859,7 +859,7 @@ ScViewData::~ScViewData() COVERITY_NOEXCEPT_FALSE
void ScViewData::UpdateCurrentTab()
{
- assert(0 <= nTabNo && static_cast<size_t>(nTabNo) < maTabData.size());
+ assert(0 <= nTabNo && o3tl::make_unsigned(nTabNo) < maTabData.size());
pThisTab = maTabData[nTabNo].get();
while (!pThisTab)
{
@@ -911,7 +911,7 @@ void ScViewData::DeleteTab( SCTAB nTab )
assert(nTab < static_cast<SCTAB>(maTabData.size()));
maTabData.erase(maTabData.begin() + nTab);
- if (static_cast<size_t>(nTabNo) >= maTabData.size())
+ if (o3tl::make_unsigned(nTabNo) >= maTabData.size())
{
EnsureTabDataSize(1);
nTabNo = maTabData.size() - 1;
@@ -927,7 +927,7 @@ void ScViewData::DeleteTabs( SCTAB nTab, SCTAB nSheets )
mpMarkData->DeleteTab( nTab + i );
}
maTabData.erase(maTabData.begin() + nTab, maTabData.begin()+ nTab+nSheets);
- if (static_cast<size_t>(nTabNo) >= maTabData.size())
+ if (o3tl::make_unsigned(nTabNo) >= maTabData.size())
{
EnsureTabDataSize(1);
nTabNo = maTabData.size() - 1;
diff --git a/sd/qa/unit/export-tests.cxx b/sd/qa/unit/export-tests.cxx
index b9a32f453452..6446db8ddb89 100644
--- a/sd/qa/unit/export-tests.cxx
+++ b/sd/qa/unit/export-tests.cxx
@@ -1063,7 +1063,7 @@ void SdExportTest::testBulletsAsImage()
CPPUNIT_ASSERT_MESSAGE(sFailed.getStr(), xBitmap.is());
Graphic aGraphic(uno::Reference<graphic::XGraphic>(xBitmap, uno::UNO_QUERY));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessageBase.getStr(), GraphicType::Bitmap, aGraphic.GetType());
- CPPUNIT_ASSERT_MESSAGE(sFailedMessageBase.getStr(), aGraphic.GetSizeBytes() > sal_uLong(0));
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessageBase.getStr(), aGraphic.GetSizeBytes() > o3tl::make_unsigned(0));
if (nExportFormat == ODP || nExportFormat == PPT)
{
diff --git a/sd/qa/unit/sdmodeltestbase.hxx b/sd/qa/unit/sdmodeltestbase.hxx
index 1bb6828a53ea..a490dcee60ee 100644
--- a/sd/qa/unit/sdmodeltestbase.hxx
+++ b/sd/qa/unit/sdmodeltestbase.hxx
@@ -26,7 +26,7 @@
#include <tools/color.hxx>
#include <comphelper/fileformat.h>
#include <comphelper/processfactory.hxx>
-
+#include <o3tl/safeint.hxx>
#include <rtl/strbuf.hxx>
#include <sfx2/docfile.hxx>
#include <sfx2/docfilt.hxx>
@@ -194,7 +194,7 @@ protected:
FileFormat* getFormat(sal_Int32 nExportType)
{
FileFormat* pFormat = &aFileFormats[0];
- if (static_cast<sal_uInt32>(nExportType) < SAL_N_ELEMENTS(aFileFormats))
+ if (o3tl::make_unsigned(nExportType) < SAL_N_ELEMENTS(aFileFormats))
pFormat = &aFileFormats[nExportType];
return pFormat;
}
diff --git a/sd/source/core/CustomAnimationEffect.cxx b/sd/source/core/CustomAnimationEffect.cxx
index 439cb07356b3..e5da2e3fbadd 100644
--- a/sd/source/core/CustomAnimationEffect.cxx
+++ b/sd/source/core/CustomAnimationEffect.cxx
@@ -69,6 +69,7 @@
#include <cppuhelper/implbase.hxx>
#include <drawinglayer/geometry/viewinformation2d.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/sdr/contact/viewcontact.hxx>
#include <svx/svdopath.hxx>
#include <svx/svdpage.hxx>
@@ -548,7 +549,7 @@ bool CustomAnimationEffect::checkForText( const std::vector<sal_Int32>* paragrap
if ( paragraphNumberingLevel )
{
bHasText = !paragraphNumberingLevel->empty();
- if (nPara >= 0 && static_cast<size_t>(nPara) < paragraphNumberingLevel->size())
+ if (nPara >= 0 && o3tl::make_unsigned(nPara) < paragraphNumberingLevel->size())
nParaDepth = paragraphNumberingLevel->at(nPara);
}
else
diff --git a/sd/source/core/sdpage.cxx b/sd/source/core/sdpage.cxx
index 79632feb8559..5ce948618f18 100644
--- a/sd/source/core/sdpage.cxx
+++ b/sd/source/core/sdpage.cxx
@@ -59,6 +59,7 @@
#include <rtl/ustring.hxx>
#include <sal/log.hxx>
#include <o3tl/enumarray.hxx>
+#include <o3tl/safeint.hxx>
#include <xmloff/autolayout.hxx>
#include <Outliner.hxx>
@@ -236,7 +237,7 @@ SdrObject* SdPage::GetPresObj(PresObjKind eObjKind, int nIndex, bool bFuzzySearc
if( nIndex > 0 )
nIndex--;
- if( (nIndex >= 0) && ( aMatches.size() > static_cast<unsigned int>(nIndex)) )
+ if( (nIndex >= 0) && ( aMatches.size() > o3tl::make_unsigned(nIndex)) )
{
if( aMatches.size() > 1 )
std::nth_element( aMatches.begin(), aMatches.begin() + nIndex, aMatches.end(),
diff --git a/sd/source/filter/html/htmlex.cxx b/sd/source/filter/html/htmlex.cxx
index 8ee778b8944b..7e60955b1c41 100644
--- a/sd/source/filter/html/htmlex.cxx
+++ b/sd/source/filter/html/htmlex.cxx
@@ -25,6 +25,7 @@
#include <sal/log.hxx>
#include <rtl/tencinfo.h>
#include <comphelper/processfactory.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <unotools/pathoptions.hxx>
#include <unotools/ucbstreamhelper.hxx>
@@ -1067,7 +1068,7 @@ OUString HtmlExport::DocumentMetadata() const
&aNonConvertableCharacters);
const sal_uInt64 nLen = aStream.GetSize();
- OSL_ENSURE(nLen < static_cast<sal_uInt64>(SAL_MAX_INT32), "Stream can't fit in OString");
+ OSL_ENSURE(nLen < o3tl::make_unsigned(SAL_MAX_INT32), "Stream can't fit in OString");
OString aData(static_cast<const char*>(aStream.GetData()), static_cast<sal_Int32>(nLen));
return OStringToOUString(aData, RTL_TEXTENCODING_UTF8);
diff --git a/sd/source/filter/pdf/sdpdffilter.cxx b/sd/source/filter/pdf/sdpdffilter.cxx
index 88986fe0e477..b7bf48547bed 100644
--- a/sd/source/filter/pdf/sdpdffilter.cxx
+++ b/sd/source/filter/pdf/sdpdffilter.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <sfx2/docfile.hxx>
#include <svx/svdograf.hxx>
@@ -71,7 +74,7 @@ bool SdPdfFilter::Import()
const Size& aSize = aPair.second;
const sal_Int32 nPageNumber = rGraphic.getPageNumber();
- assert(nPageNumber >= 0 && static_cast<size_t>(nPageNumber) < aGraphics.size());
+ assert(nPageNumber >= 0 && o3tl::make_unsigned(nPageNumber) < aGraphics.size());
// Create the page and insert the Graphic.
SdPage* pPage = mrDocument.GetSdPage(nPageNumber, PageKind::Standard);
diff --git a/sd/source/ui/accessibility/AccessibleSlideSorterView.cxx b/sd/source/ui/accessibility/AccessibleSlideSorterView.cxx
index cb024f1f849d..305f8abaa3d4 100644
--- a/sd/source/ui/accessibility/AccessibleSlideSorterView.cxx
+++ b/sd/source/ui/accessibility/AccessibleSlideSorterView.cxx
@@ -42,6 +42,7 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <comphelper/accessibleeventnotifier.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <rtl/ref.hxx>
#include <sal/log.hxx>
@@ -730,7 +731,7 @@ AccessibleSlideSorterObject* AccessibleSlideSorterView::Implementation::GetAcces
{
AccessibleSlideSorterObject* pChild = nullptr;
- if (nIndex>=0 && static_cast<sal_uInt32>(nIndex)<maPageObjects.size())
+ if (nIndex>=0 && o3tl::make_unsigned(nIndex)<maPageObjects.size())
{
if (maPageObjects[nIndex] == nullptr)
{
@@ -755,7 +756,7 @@ AccessibleSlideSorterObject* AccessibleSlideSorterView::Implementation::GetAcces
}
else
{
- OSL_ASSERT(nIndex>=0 && static_cast<sal_uInt32>(nIndex)<maPageObjects.size());
+ OSL_ASSERT(nIndex>=0 && o3tl::make_unsigned(nIndex)<maPageObjects.size());
}
return pChild;
diff --git a/sd/source/ui/animations/SlideTransitionPane.cxx b/sd/source/ui/animations/SlideTransitionPane.cxx
index a389e08763f1..12fbca7ae85f 100644
--- a/sd/source/ui/animations/SlideTransitionPane.cxx
+++ b/sd/source/ui/animations/SlideTransitionPane.cxx
@@ -46,6 +46,7 @@
#include <undoanim.hxx>
#include <optsitem.hxx>
+#include <o3tl/safeint.hxx>
#include <sfx2/sidebar/Theme.hxx>
#include <algorithm>
@@ -303,7 +304,7 @@ OUString lcl_getSoundFileURL(
DBG_ASSERT( static_cast<sal_uInt32>(rListBox.get_count() - 3) == rSoundList.size(),
"Sound list-box is not synchronized to sound list" );
nPos -= 3;
- if( rSoundList.size() > static_cast<size_t>(nPos) )
+ if( rSoundList.size() > o3tl::make_unsigned(nPos) )
return rSoundList[ nPos ];
}
diff --git a/sd/source/ui/dlg/tpaction.cxx b/sd/source/ui/dlg/tpaction.cxx
index eff5ad6cba92..4eadc2a50279 100644
--- a/sd/source/ui/dlg/tpaction.cxx
+++ b/sd/source/ui/dlg/tpaction.cxx
@@ -30,7 +30,7 @@
#include <sdattr.hrc>
#include <sfx2/sfxresid.hxx>
#include <sfx2/strings.hrc>
-
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <sfx2/app.hxx>
#include <unotools/pathoptions.hxx>
@@ -667,7 +667,7 @@ presentation::ClickAction SdTPAction::GetActualClickAction()
{
presentation::ClickAction eCA = presentation::ClickAction_NONE;
int nPos = m_xLbAction->get_active();
- if (nPos != -1 && static_cast<size_t>(nPos) < maCurrentActions.size())
+ if (nPos != -1 && o3tl::make_unsigned(nPos) < maCurrentActions.size())
eCA = maCurrentActions[ nPos ];
return eCA;
}
@@ -753,7 +753,7 @@ OUString SdTPAction::GetEditText( bool bFullDocDestination )
case presentation::ClickAction_VERB:
{
const int nPos = m_xLbOLEAction->get_selected_index();
- if (nPos != -1 && static_cast<size_t>(nPos) < aVerbVector.size() )
+ if (nPos != -1 && o3tl::make_unsigned(nPos) < aVerbVector.size() )
aStr = OUString::number( aVerbVector[ nPos ] );
return aStr;
}
diff --git a/sd/source/ui/sidebar/MasterPageContainer.cxx b/sd/source/ui/sidebar/MasterPageContainer.cxx
index 60bc2ba3dd40..d63bc2664cbb 100644
--- a/sd/source/ui/sidebar/MasterPageContainer.cxx
+++ b/sd/source/ui/sidebar/MasterPageContainer.cxx
@@ -42,6 +42,7 @@
#include <sdpage.hxx>
#include <sdresid.hxx>
#include <tools/TimerBasedTaskExecution.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <osl/getglobalmutex.hxx>
#include <xmloff/autolayout.hxx>
@@ -673,13 +674,13 @@ MasterPageContainer::Token MasterPageContainer::Implementation::PutMasterPage (
bool MasterPageContainer::Implementation::HasToken (Token aToken) const
{
return aToken>=0
- && static_cast<unsigned>(aToken)<maContainer.size()
+ && o3tl::make_unsigned(aToken)<maContainer.size()
&& maContainer[aToken].get()!=nullptr;
}
SharedMasterPageDescriptor MasterPageContainer::Implementation::GetDescriptor (Token aToken) const
{
- if (aToken>=0 && static_cast<unsigned>(aToken)<maContainer.size())
+ if (aToken>=0 && o3tl::make_unsigned(aToken)<maContainer.size())
return maContainer[aToken];
else
return SharedMasterPageDescriptor();
@@ -958,7 +959,7 @@ bool MasterPageContainer::Implementation::UpdateDescriptor (
void MasterPageContainer::Implementation::ReleaseDescriptor (Token aToken)
{
- if (aToken>=0 && static_cast<unsigned>(aToken)<maContainer.size())
+ if (aToken>=0 && o3tl::make_unsigned(aToken)<maContainer.size())
{
maContainer[aToken].reset();
}
diff --git a/sd/source/ui/sidebar/MasterPagesSelector.cxx b/sd/source/ui/sidebar/MasterPagesSelector.cxx
index 8ca3fe8e7f0d..560f061db87c 100644
--- a/sd/source/ui/sidebar/MasterPagesSelector.cxx
+++ b/sd/source/ui/sidebar/MasterPagesSelector.cxx
@@ -34,6 +34,7 @@
#include <SlideSorterViewShell.hxx>
#include "PreviewValueSet.hxx"
#include <ViewShellBase.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/image.hxx>
#include <vcl/floatwin.hxx>
@@ -429,7 +430,7 @@ MasterPagesSelector::UserData* MasterPagesSelector::GetUserData (int nIndex) con
{
const ::osl::MutexGuard aGuard (maMutex);
- if (nIndex>0 && static_cast<unsigned int>(nIndex)<=PreviewValueSet::GetItemCount())
+ if (nIndex>0 && o3tl::make_unsigned(nIndex)<=PreviewValueSet::GetItemCount())
return static_cast<UserData*>(PreviewValueSet::GetItemData(static_cast<sal_uInt16>(nIndex)));
else
return nullptr;
diff --git a/sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx b/sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx
index 46293b1b7981..a219a9c2ebf4 100644
--- a/sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx
+++ b/sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
+
#include <controller/SlsAnimationFunction.hxx>
namespace sd::slidesorter::controller {
@@ -114,7 +118,7 @@ double AnimationParametricFunction::operator() (const double nX)
if (nIndex0<=0)
return maY[0];
- else if (sal_uInt32(nIndex0)>=maY.size() || nIndex1>=maY.size())
+ else if (o3tl::make_unsigned(nIndex0)>=maY.size() || nIndex1>=maY.size())
return maY[maY.size()-1];
const double nU ((nX-nX1) / (nX0 - nX1));
diff --git a/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx b/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx
index 01446d707ae8..a1a94040ea15 100644
--- a/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx
+++ b/sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx
@@ -30,6 +30,7 @@
#include <drawdoc.hxx>
#include <Window.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/virdev.hxx>
#include <basegfx/range/b2drectangle.hxx>
#include <basegfx/polygon/b2dpolygon.hxx>
@@ -155,7 +156,7 @@ Point InsertionIndicatorOverlay::PaintRepresentatives (
const BitmapEx aExclusionOverlay (mrSlideSorter.GetTheme()->GetIcon(Theme::Icon_HideSlideOverlay));
for (sal_Int32 nIndex=2; nIndex>=0; --nIndex)
{
- if (rRepresentatives.size() <= sal_uInt32(nIndex))
+ if (rRepresentatives.size() <= o3tl::make_unsigned(nIndex))
continue;
switch(nIndex)
{
diff --git a/sd/source/ui/slidesorter/view/SlsLayeredDevice.cxx b/sd/source/ui/slidesorter/view/SlsLayeredDevice.cxx
index 51f6e12b4483..c111f807be24 100644
--- a/sd/source/ui/slidesorter/view/SlsLayeredDevice.cxx
+++ b/sd/source/ui/slidesorter/view/SlsLayeredDevice.cxx
@@ -22,6 +22,7 @@
#include <vcl/virdev.hxx>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tools/gen.hxx>
@@ -174,9 +175,9 @@ void LayeredDevice::Invalidate (
const ::tools::Rectangle& rInvalidationArea,
const sal_Int32 nLayer)
{
- if (nLayer<0 || size_t(nLayer)>=mpLayers->size())
+ if (nLayer<0 || o3tl::make_unsigned(nLayer)>=mpLayers->size())
{
- OSL_ASSERT(nLayer>=0 && size_t(nLayer)<mpLayers->size());
+ OSL_ASSERT(nLayer>=0 && o3tl::make_unsigned(nLayer)<mpLayers->size());
return;
}
@@ -212,7 +213,7 @@ void LayeredDevice::RegisterPainter (
}
// Provide the layers.
- if (sal_uInt32(nLayer) >= mpLayers->size())
+ if (o3tl::make_unsigned(nLayer) >= mpLayers->size())
{
const sal_Int32 nOldLayerCount (mpLayers->size());
mpLayers->resize(nLayer+1);
@@ -238,9 +239,9 @@ void LayeredDevice::RemovePainter (
OSL_ASSERT(rpPainter);
return;
}
- if (nLayer<0 || size_t(nLayer)>=mpLayers->size())
+ if (nLayer<0 || o3tl::make_unsigned(nLayer)>=mpLayers->size())
{
- OSL_ASSERT(nLayer>=0 && size_t(nLayer)<mpLayers->size());
+ OSL_ASSERT(nLayer>=0 && o3tl::make_unsigned(nLayer)<mpLayers->size());
return;
}
diff --git a/sdext/source/pdfimport/pdfparse/pdfparse.cxx b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
index f973e24931c0..eff5b774597b 100644
--- a/sdext/source/pdfimport/pdfparse/pdfparse.cxx
+++ b/sdext/source/pdfimport/pdfparse/pdfparse.cxx
@@ -36,6 +36,7 @@
#include <string.h>
+#include <o3tl/safeint.hxx>
#include <rtl/strbuf.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -67,11 +68,11 @@ class StringEmitContext : public EmitContext
}
virtual unsigned int getCurPos() throw() override { return m_aBuf.getLength(); }
virtual bool copyOrigBytes( unsigned int nOrigOffset, unsigned int nLen ) throw() override
- { return (nOrigOffset+nLen < static_cast<unsigned int>(m_aBuf.getLength()) ) &&
+ { return (nOrigOffset+nLen < o3tl::make_unsigned(m_aBuf.getLength()) ) &&
write( m_aBuf.getStr() + nOrigOffset, nLen ); }
virtual unsigned int readOrigBytes( unsigned int nOrigOffset, unsigned int nLen, void* pBuf ) throw() override
{
- if( nOrigOffset+nLen < static_cast<unsigned int>(m_aBuf.getLength()) )
+ if( nOrigOffset+nLen < o3tl::make_unsigned(m_aBuf.getLength()) )
{
memcpy( pBuf, m_aBuf.getStr()+nOrigOffset, nLen );
return nLen;
diff --git a/sdext/source/presenter/PresenterAccessibility.cxx b/sdext/source/presenter/PresenterAccessibility.cxx
index c69f3f15b96f..59397990458e 100644
--- a/sdext/source/presenter/PresenterAccessibility.cxx
+++ b/sdext/source/presenter/PresenterAccessibility.cxx
@@ -39,6 +39,7 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/implbase.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <algorithm>
@@ -1297,7 +1298,7 @@ sal_Int32 SAL_CALL AccessibleRelationSet::getRelationCount()
AccessibleRelation SAL_CALL AccessibleRelationSet::getRelation (sal_Int32 nIndex)
{
- if (nIndex<0 && sal_uInt32(nIndex)>=maRelations.size())
+ if (nIndex<0 && o3tl::make_unsigned(nIndex)>=maRelations.size())
return AccessibleRelation();
else
return maRelations[nIndex];
diff --git a/sdext/source/presenter/PresenterTextView.cxx b/sdext/source/presenter/PresenterTextView.cxx
index e4f9351f01e1..f56c5ed812d2 100644
--- a/sdext/source/presenter/PresenterTextView.cxx
+++ b/sdext/source/presenter/PresenterTextView.cxx
@@ -35,6 +35,7 @@
#include <com/sun/star/rendering/CompositeOperation.hpp>
#include <com/sun/star/rendering/TextDirection.hpp>
#include <com/sun/star/text/WritingMode2.hpp>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
using namespace ::com::sun::star;
@@ -236,7 +237,7 @@ void PresenterTextView::MoveCaret (
nCharacterIndex = 0;
nRemainingDistance = 0;
}
- else if (sal_uInt32(nParagraphIndex) >= maParagraphs.size())
+ else if (o3tl::make_unsigned(nParagraphIndex) >= maParagraphs.size())
{
nParagraphIndex = maParagraphs.size()-1;
pParagraph = GetParagraph(nParagraphIndex);
@@ -620,7 +621,7 @@ sal_Int32 PresenterTextParagraph::GetWordBoundary(
if (nIndex < 0)
return -1;
- else if (sal_uInt32(nIndex)>=maWordBoundaries.size())
+ else if (o3tl::make_unsigned(nIndex)>=maWordBoundaries.size())
return -1;
else
return maWordBoundaries[nIndex];
diff --git a/sfx2/source/appl/sfxhelp.cxx b/sfx2/source/appl/sfxhelp.cxx
index 511acc50f07f..2242e06ab7d4 100644
--- a/sfx2/source/appl/sfxhelp.cxx
+++ b/sfx2/source/appl/sfxhelp.cxx
@@ -51,6 +51,7 @@
#include <unotools/pathoptions.hxx>
#include <rtl/byteseq.hxx>
#include <rtl/ustring.hxx>
+#include <o3tl/safeint.hxx>
#include <officecfg/Office/Common.hxx>
#include <osl/process.h>
#include <osl/file.hxx>
@@ -782,7 +783,7 @@ bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) {
if (instance) {
static constexpr auto keyPath = OUStringLiteral("app-path=");
static constexpr auto keyExtensions = OUStringLiteral("app-extensions=");
- if (!havePath && line.length() >= unsigned(keyPath.size)
+ if (!havePath && line.length() >= o3tl::make_unsigned(keyPath.size)
&& line.substr(0, keyPath.size) == keyPath.data)
{
auto const value = line.substr(keyPath.size);
@@ -800,7 +801,7 @@ bool rewriteFlatpakHelpRootUrl(OUString * helpRootUrl) {
throw Failure();
}
havePath = true;
- } else if (!haveExtensions && line.length() >= unsigned(keyExtensions.size)
+ } else if (!haveExtensions && line.length() >= o3tl::make_unsigned(keyExtensions.size)
&& line.substr(0, keyExtensions.size) == keyExtensions.data)
{
auto const value = line.substr(keyExtensions.size);
diff --git a/sfx2/source/bastyp/mieclip.cxx b/sfx2/source/bastyp/mieclip.cxx
index c99c61f045d6..83920a1752ad 100644
--- a/sfx2/source/bastyp/mieclip.cxx
+++ b/sfx2/source/bastyp/mieclip.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <tools/stream.hxx>
#include <sfx2/mieclip.hxx>
@@ -56,7 +59,7 @@ SvStream* MSE40HTMLClipFormatObj::IsValid( SvStream& rStream )
sBaseURL = OStringToOUString( sLine.copy(nIndex), RTL_TEXTENCODING_UTF8 );
if (nEnd >= 0 && nStt >= 0 &&
- (!sBaseURL.isEmpty() || rStream.Tell() >= static_cast<sal_uInt64>(nStt)))
+ (!sBaseURL.isEmpty() || rStream.Tell() >= o3tl::make_unsigned(nStt)))
{
bRet = true;
break;
diff --git a/sfx2/source/dialog/dockwin.cxx b/sfx2/source/dialog/dockwin.cxx
index a2ad4336ad7f..8b787fc69bd2 100644
--- a/sfx2/source/dialog/dockwin.cxx
+++ b/sfx2/source/dialog/dockwin.cxx
@@ -26,6 +26,7 @@
#include <vcl/svapp.hxx>
#include <vcl/timer.hxx>
#include <vcl/idle.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/instance.hxx>
#include <toolkit/helper/vclunohelper.hxx>
@@ -296,7 +297,7 @@ namespace
static bool lcl_checkDockingWindowID( sal_uInt16 nID )
{
- return !(nID < SID_DOCKWIN_START || nID >= sal_uInt16(SID_DOCKWIN_START+NUM_OF_DOCKINGWINDOWS));
+ return !(nID < SID_DOCKWIN_START || nID >= o3tl::make_unsigned(SID_DOCKWIN_START+NUM_OF_DOCKINGWINDOWS));
}
static SfxWorkWindow* lcl_getWorkWindowFromXFrame( const uno::Reference< frame::XFrame >& rFrame )
diff --git a/sfx2/source/sidebar/TabBar.cxx b/sfx2/source/sidebar/TabBar.cxx
index 023233ff3d22..1acd7e10f619 100644
--- a/sfx2/source/sidebar/TabBar.cxx
+++ b/sfx2/source/sidebar/TabBar.cxx
@@ -30,6 +30,7 @@
#include <sfx2/sfxresid.hxx>
#include <comphelper/processfactory.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/commandevent.hxx>
#include <vcl/event.hxx>
#include <vcl/image.hxx>
@@ -312,14 +313,14 @@ IMPL_LINK_NOARG(TabBar::Item, HandleClick, Button*, void)
OUString const & TabBar::GetDeckIdForIndex (const sal_Int32 nIndex) const
{
- if (nIndex<0 || static_cast<size_t>(nIndex)>=maItems.size())
+ if (nIndex<0 || o3tl::make_unsigned(nIndex)>=maItems.size())
throw RuntimeException();
return maItems[nIndex].msDeckId;
}
void TabBar::ToggleHideFlag (const sal_Int32 nIndex)
{
- if (nIndex<0 || static_cast<size_t>(nIndex) >= maItems.size())
+ if (nIndex<0 || o3tl::make_unsigned(nIndex) >= maItems.size())
throw RuntimeException();
maItems[nIndex].mbIsHidden = ! maItems[nIndex].mbIsHidden;
diff --git a/slideshow/source/engine/opengl/TransitionImpl.hxx b/slideshow/source/engine/opengl/TransitionImpl.hxx
index 2e50b8ba5418..2831685cd3a7 100644
--- a/slideshow/source/engine/opengl/TransitionImpl.hxx
+++ b/slideshow/source/engine/opengl/TransitionImpl.hxx
@@ -32,6 +32,7 @@
#include <epoxy/gl.h>
#include <glm/gtc/type_ptr.hpp>
+#include <o3tl/safeint.hxx>
#include <sal/types.h>
#include <limits>
@@ -340,7 +341,7 @@ public:
int getVerticesCount() const
{
- assert(Vertices.size() < unsigned(std::numeric_limits<int>::max()));
+ assert(Vertices.size() < o3tl::make_unsigned(std::numeric_limits<int>::max()));
return int(unsigned(Vertices.size()));
}
diff --git a/slideshow/source/engine/shapes/drawshapesubsetting.cxx b/slideshow/source/engine/shapes/drawshapesubsetting.cxx
index 08f2dbba9481..4bc51e2dc08d 100644
--- a/slideshow/source/engine/shapes/drawshapesubsetting.cxx
+++ b/slideshow/source/engine/shapes/drawshapesubsetting.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
#include <sal/log.hxx>
@@ -85,7 +87,7 @@ namespace slideshow
// action).
const sal_Int32 nIndex( nLastTextActionIndex + pAct->GetValue() );
- ENSURE_OR_THROW( static_cast< ::std::size_t >(nIndex) < maActionClassVector.size(),
+ ENSURE_OR_THROW( o3tl::make_unsigned(nIndex) < maActionClassVector.size(),
"DrawShapeSubsetting::ensureInitializedNodeTree(): sentence index out of range" );
maActionClassVector[ nIndex ] = CLASS_CHARACTER_CELL_END;
@@ -99,7 +101,7 @@ namespace slideshow
// action).
const sal_Int32 nIndex( nLastTextActionIndex + pAct->GetValue() );
- ENSURE_OR_THROW( static_cast< ::std::size_t >(nIndex) < maActionClassVector.size(),
+ ENSURE_OR_THROW( o3tl::make_unsigned(nIndex) < maActionClassVector.size(),
"DrawShapeSubsetting::ensureInitializedNodeTree(): sentence index out of range" );
maActionClassVector[ nIndex ] = CLASS_WORD_END;
@@ -113,7 +115,7 @@ namespace slideshow
// action).
const sal_Int32 nIndex( nLastTextActionIndex + pAct->GetValue() );
- ENSURE_OR_THROW( static_cast< ::std::size_t >(nIndex) < maActionClassVector.size(),
+ ENSURE_OR_THROW( o3tl::make_unsigned(nIndex) < maActionClassVector.size(),
"DrawShapeSubsetting::ensureInitializedNodeTree(): sentence index out of range" );
maActionClassVector[ nIndex ] = CLASS_SENTENCE_END;
diff --git a/solenv/CompilerTest_compilerplugins_clang.mk b/solenv/CompilerTest_compilerplugins_clang.mk
index 05c470df005d..999d838ee36c 100644
--- a/solenv/CompilerTest_compilerplugins_clang.mk
+++ b/solenv/CompilerTest_compilerplugins_clang.mk
@@ -93,6 +93,7 @@ $(eval $(call gb_CompilerTest_add_exception_objects,compilerplugins_clang, \
compilerplugins/clang/test/unoany \
compilerplugins/clang/test/unoquery \
compilerplugins/clang/test/unreffun \
+ compilerplugins/clang/test/unsignedcompare \
compilerplugins/clang/test/unusedenumconstants \
compilerplugins/clang/test/unusedfields \
compilerplugins/clang/test/unusedindex \
diff --git a/sot/source/sdstor/stgelem.cxx b/sot/source/sdstor/stgelem.cxx
index f902c5f1944a..43f4faf0251d 100644
--- a/sot/source/sdstor/stgelem.cxx
+++ b/sot/source/sdstor/stgelem.cxx
@@ -19,6 +19,8 @@
#include <string.h>
+
+#include <o3tl/safeint.hxx>
#include <rtl/ustring.hxx>
#include <com/sun/star/lang/Locale.hpp>
#include <unotools/charclass.hxx>
@@ -438,7 +440,7 @@ bool StgEntry::Load(const void* pFrom, sal_uInt32 nBufSize, sal_uInt64 nUnderlyi
// in this case it would mean a stream of more than 2Gb
return false;
}
- if (static_cast<sal_uInt64>(m_nSize) > nUnderlyingStreamSize)
+ if (o3tl::make_unsigned(m_nSize) > nUnderlyingStreamSize)
{
// surely an entry cannot be larger than the underlying file
return false;
diff --git a/starmath/source/AccessibleSmElementsControl.cxx b/starmath/source/AccessibleSmElementsControl.cxx
index 3e9c2d84e792..5061d8cf5a35 100644
--- a/starmath/source/AccessibleSmElementsControl.cxx
+++ b/starmath/source/AccessibleSmElementsControl.cxx
@@ -31,6 +31,7 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <cppuhelper/supportsservice.hxx>
#include <cppuhelper/typeprovider.hxx>
+#include <o3tl/safeint.hxx>
#include <toolkit/helper/convert.hxx>
#include <unotools/accessiblerelationsethelper.hxx>
#include <unotools/accessiblestatesethelper.hxx>
@@ -268,7 +269,7 @@ void AccessibleSmElementsControl::selectAccessibleChild(sal_Int32 nChildIndex)
OExternalLockGuard aGuard(this);
if ((!m_pControl) || nChildIndex < 0
- || static_cast<size_t>(nChildIndex) >= m_aAccessibleChildren.size())
+ || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size())
throw lang::IndexOutOfBoundsException();
m_pControl->setItemHighlighted(nChildIndex);
@@ -278,7 +279,7 @@ sal_Bool AccessibleSmElementsControl::isAccessibleChildSelected(sal_Int32 nChild
{
OExternalLockGuard aGuard(this);
if ((!m_pControl) || nChildIndex < 0
- || static_cast<size_t>(nChildIndex) >= m_aAccessibleChildren.size())
+ || o3tl::make_unsigned(nChildIndex) >= m_aAccessibleChildren.size())
throw lang::IndexOutOfBoundsException();
return (m_pControl->itemHighlighted() == nChildIndex);
diff --git a/stoc/source/typeconv/convert.cxx b/stoc/source/typeconv/convert.cxx
index 97cb4bebd62c..07e2d859c045 100644
--- a/stoc/source/typeconv/convert.cxx
+++ b/stoc/source/typeconv/convert.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/supportsservice.hxx>
@@ -300,11 +301,11 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6
// UNSIGNED HYPER
case TypeClass_UNSIGNED_HYPER:
{
- nRet = static_cast<sal_Int64>(*o3tl::forceAccess<sal_uInt64>(rAny));
- if ((min < 0 || static_cast<sal_uInt64>(nRet) >= static_cast<sal_uInt64>(min)) && // lower bound
- static_cast<sal_uInt64>(nRet) <= max) // upper bound
+ auto const n = *o3tl::forceAccess<sal_uInt64>(rAny);
+ if ((min < 0 || n >= o3tl::make_unsigned(min)) && // lower bound
+ n <= max) // upper bound
{
- return nRet;
+ return static_cast<sal_Int64>(n);
}
throw CannotConvertException(
"UNSIGNED HYPER out of range!",
@@ -348,7 +349,7 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6
Reference<XInterface>(), aDestinationClass, FailReason::IS_NOT_NUMBER, 0 );
}
nRet = nVal;
- if (nVal >= min && (nVal < 0 || static_cast<sal_uInt64>(nVal) <= max))
+ if (nVal >= min && (nVal < 0 || o3tl::make_unsigned(nVal) <= max))
return nRet;
throw CannotConvertException(
"STRING value out of range!",
@@ -361,7 +362,7 @@ sal_Int64 TypeConverter_Impl::toHyper( const Any& rAny, sal_Int64 min, sal_uInt6
Reference<XInterface>(), aDestinationClass, FailReason::TYPE_NOT_SUPPORTED, 0 );
}
- if (nRet >= min && (nRet < 0 || static_cast<sal_uInt64>(nRet) <= max))
+ if (nRet >= min && (nRet < 0 || o3tl::make_unsigned(nRet) <= max))
return nRet;
throw CannotConvertException(
"VALUE is out of range!",
diff --git a/svl/source/items/macitem.cxx b/svl/source/items/macitem.cxx
index 03bd8f6d53e2..64a22aa0039c 100644
--- a/svl/source/items/macitem.cxx
+++ b/svl/source/items/macitem.cxx
@@ -19,6 +19,7 @@
#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <comphelper/fileformat.h>
#include <tools/stream.hxx>
@@ -99,7 +100,7 @@ void SvxMacroTableDtor::Read( SvStream& rStrm )
nMinRecordSize+=2;
const size_t nMaxRecords = rStrm.remainingSize() / nMinRecordSize;
- if (static_cast<size_t>(nMacro) > nMaxRecords)
+ if (o3tl::make_unsigned(nMacro) > nMaxRecords)
{
SAL_WARN("editeng", "Parsing error: " << nMaxRecords <<
" max possible entries, but " << nMacro<< " claimed, truncating");
diff --git a/svl/source/misc/strmadpt.cxx b/svl/source/misc/strmadpt.cxx
index 0ffa3540c112..d99aae4687ce 100644
--- a/svl/source/misc/strmadpt.cxx
+++ b/svl/source/misc/strmadpt.cxx
@@ -27,7 +27,7 @@
#include <com/sun/star/io/XInputStream.hpp>
#include <com/sun/star/io/XOutputStream.hpp>
#include <com/sun/star/io/XSeekable.hpp>
-
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <svl/instrm.hxx>
#include <svl/outstrm.hxx>
@@ -254,7 +254,7 @@ sal_uInt64 SvInputStream::SeekPos(sal_uInt64 const nPos)
{
sal_Int64 nLength = m_xSeekable->getLength();
OSL_ASSERT(nLength >= 0);
- if (static_cast<sal_uInt64>(nLength)
+ if (o3tl::make_unsigned(nLength)
< STREAM_SEEK_TO_END)
{
m_nSeekedFrom = Tell();
diff --git a/svl/source/numbers/zforscan.cxx b/svl/source/numbers/zforscan.cxx
index 1216ae6756a7..1434bbf08636 100644
--- a/svl/source/numbers/zforscan.cxx
+++ b/svl/source/numbers/zforscan.cxx
@@ -20,6 +20,7 @@
#include <stdlib.h>
#include <comphelper/string.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <tools/debug.hxx>
#include <i18nlangtag/mslangid.hxx>
@@ -1634,7 +1635,7 @@ bool ImpSvNumberformatScan::InsertSymbol( sal_uInt16 & nPos, svt::NfSymbolType e
}
else
{
- if (static_cast<size_t>(nStringsCnt + 1) >= NF_MAX_FORMAT_SYMBOLS)
+ if (o3tl::make_unsigned(nStringsCnt + 1) >= NF_MAX_FORMAT_SYMBOLS)
{
return false;
}
diff --git a/svtools/source/brwbox/brwbox1.cxx b/svtools/source/brwbox/brwbox1.cxx
index 2aead90c8d04..e9be5c9bc4a3 100644
--- a/svtools/source/brwbox/brwbox1.cxx
+++ b/svtools/source/brwbox/brwbox1.cxx
@@ -20,6 +20,7 @@
#include <svtools/brwbox.hxx>
#include <svtools/brwhead.hxx>
#include <o3tl/numeric.hxx>
+#include <o3tl/safeint.hxx>
#include "datwin.hxx"
#include <tools/debug.hxx>
#include <tools/fract.hxx>
@@ -523,7 +524,7 @@ void BrowseBox::SetColumnWidth( sal_uInt16 nItemId, sal_uLong nWidth )
nMaxWidth -= pDataWin->bAutoSizeLastCol
? GetFieldRect(nItemId).Left()
: GetFrozenWidth();
- if ( pDataWin->bAutoSizeLastCol || nWidth > static_cast<sal_uLong>(nMaxWidth) )
+ if ( pDataWin->bAutoSizeLastCol || nWidth > o3tl::make_unsigned(nMaxWidth) )
{
nWidth = nMaxWidth > 16 ? nMaxWidth : nOldWidth;
}
diff --git a/svtools/source/brwbox/brwbox2.cxx b/svtools/source/brwbox/brwbox2.cxx
index 8daede5fa7b9..877277701e14 100644
--- a/svtools/source/brwbox/brwbox2.cxx
+++ b/svtools/source/brwbox/brwbox2.cxx
@@ -804,7 +804,7 @@ void BrowseBox::ImplPaintData(OutputDevice& _rOut, const tools::Rectangle& _rRec
// redraw the invalid fields
for ( sal_uLong nRelRow = nRelTopRow;
- nRelRow <= nRelBottomRow && static_cast<sal_uLong>(nTopRow)+nRelRow < static_cast<sal_uLong>(nRowCount);
+ nRelRow <= nRelBottomRow && static_cast<sal_uLong>(nTopRow)+nRelRow < o3tl::make_unsigned(nRowCount);
++nRelRow, aPos.AdjustY(nDataRowHeigt ) )
{
// get row
diff --git a/svtools/source/control/valueset.cxx b/svtools/source/control/valueset.cxx
index 4c5fb740508c..dce387faf942 100644
--- a/svtools/source/control/valueset.cxx
+++ b/svtools/source/control/valueset.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <tools/stream.hxx>
#include <comphelper/base64.hxx>
@@ -456,7 +459,7 @@ void ValueSet::Format(vcl::RenderContext& rRenderContext)
}
else
{
- if (mnFirstLine > static_cast<sal_uInt16>(mnLines - mnVisLines))
+ if (mnFirstLine > o3tl::make_unsigned(mnLines - mnVisLines))
mnFirstLine = static_cast<sal_uInt16>(mnLines - mnVisLines);
}
@@ -903,7 +906,7 @@ bool ValueSet::ImplScroll(const Point& rPos)
}
else if (rPos.Y() >= maItemListRect.Bottom() - nScrollOffset)
{
- if (mnFirstLine < static_cast<sal_uInt16>(mnLines - mnVisLines))
+ if (mnFirstLine < o3tl::make_unsigned(mnLines - mnVisLines))
{
++mnFirstLine;
bScroll = true;
@@ -1737,7 +1740,7 @@ void ValueSet::SelectItem( sal_uInt16 nItemId )
mnFirstLine = nNewLine;
bNewLine = true;
}
- else if ( nNewLine > static_cast<sal_uInt16>(mnFirstLine+mnVisLines-1) )
+ else if ( nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )
{
mnFirstLine = static_cast<sal_uInt16>(nNewLine-mnVisLines+1);
bNewLine = true;
@@ -2825,7 +2828,7 @@ void SvtValueSet::SelectItem( sal_uInt16 nItemId )
mnFirstLine = nNewLine;
bNewLine = true;
}
- else if ( nNewLine > static_cast<sal_uInt16>(mnFirstLine+mnVisLines-1) )
+ else if ( nNewLine > o3tl::make_unsigned(mnFirstLine+mnVisLines-1) )
{
mnFirstLine = static_cast<sal_uInt16>(nNewLine-mnVisLines+1);
bNewLine = true;
@@ -3019,7 +3022,7 @@ void SvtValueSet::Format(vcl::RenderContext const & rRenderContext)
}
else
{
- if (mnFirstLine > static_cast<sal_uInt16>(mnLines - mnVisLines))
+ if (mnFirstLine > o3tl::make_unsigned(mnLines - mnVisLines))
mnFirstLine = static_cast<sal_uInt16>(mnLines - mnVisLines);
}
diff --git a/svtools/source/dialogs/ServerDetailsControls.cxx b/svtools/source/dialogs/ServerDetailsControls.cxx
index bfbc2e21593b..0f95e7fc3d40 100644
--- a/svtools/source/dialogs/ServerDetailsControls.cxx
+++ b/svtools/source/dialogs/ServerDetailsControls.cxx
@@ -17,6 +17,7 @@
#include <com/sun/star/sdbc/XRow.hpp>
#include <comphelper/processfactory.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/uri.hxx>
#include <ucbhelper/content.hxx>
#include <ucbhelper/commandenvironment.hxx>
@@ -385,7 +386,7 @@ void CmisDetailsContainer::selectRepository( )
{
// Get the repo ID and call the Change listener
const int nPos = m_pDialog->m_xLBRepository->get_active();
- if( static_cast<size_t>(nPos) < m_aRepoIds.size() )
+ if( o3tl::make_unsigned(nPos) < m_aRepoIds.size() )
{
m_sRepoId = m_aRepoIds[nPos];
notifyChange( );
diff --git a/svtools/source/uno/unocontroltablemodel.cxx b/svtools/source/uno/unocontroltablemodel.cxx
index 12b48d129e33..32785a32fd8d 100644
--- a/svtools/source/uno/unocontroltablemodel.cxx
+++ b/svtools/source/uno/unocontroltablemodel.cxx
@@ -26,7 +26,7 @@
#include <com/sun/star/awt/grid/XGridColumn.hpp>
#include <com/sun/star/awt/grid/XSortableGridData.hpp>
#include <com/sun/star/util/Color.hpp>
-
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <cppuhelper/weakref.hxx>
#include <tools/debug.hxx>
@@ -214,7 +214,7 @@ namespace svt { namespace table
void UnoControlTableModel::insertColumn( ColPos const i_position, Reference< XGridColumn > const & i_column )
{
DBG_CHECK_ME();
- ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
+ ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( o3tl::make_unsigned( i_position ) <= m_pImpl->aColumns.size() ),
"UnoControlTableModel::insertColumn: illegal position!" );
const PColumnModel pColumn = std::make_shared<UnoGridColumnFacade>( *this, i_column );
@@ -232,7 +232,7 @@ namespace svt { namespace table
void UnoControlTableModel::removeColumn( ColPos const i_position )
{
DBG_CHECK_ME();
- ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( size_t( i_position ) <= m_pImpl->aColumns.size() ),
+ ENSURE_OR_RETURN_VOID( ( i_position >= 0 ) && ( o3tl::make_unsigned( i_position ) <= m_pImpl->aColumns.size() ),
"UnoControlTableModel::removeColumn: illegal position!" );
// remove the column
diff --git a/svx/source/accessibility/ChildrenManagerImpl.cxx b/svx/source/accessibility/ChildrenManagerImpl.cxx
index 656db47ffc43..b24f70688b6f 100644
--- a/svx/source/accessibility/ChildrenManagerImpl.cxx
+++ b/svx/source/accessibility/ChildrenManagerImpl.cxx
@@ -37,7 +37,7 @@
#include <com/sun/star/view/XSelectionSupplier.hpp>
#include <com/sun/star/container/XChild.hpp>
#include <comphelper/types.hxx>
-
+#include <o3tl/safeint.hxx>
#include <rtl/ustring.hxx>
#include <tools/debug.hxx>
#include <svx/SvxShapeTypes.hxx>
@@ -132,7 +132,7 @@ uno::Reference<XAccessible>
ChildrenManagerImpl::GetChild (long nIndex)
{
// Check whether the given index is valid.
- if (nIndex < 0 || static_cast<unsigned long>(nIndex) >= maVisibleChildren.size())
+ if (nIndex < 0 || o3tl::make_unsigned(nIndex) >= maVisibleChildren.size())
throw lang::IndexOutOfBoundsException (
"no accessible child with index " + OUString::number(nIndex),
mxParent);
diff --git a/svx/source/accessibility/GraphCtlAccessibleContext.cxx b/svx/source/accessibility/GraphCtlAccessibleContext.cxx
index 3aff94540e9a..c5d2321b5519 100644
--- a/svx/source/accessibility/GraphCtlAccessibleContext.cxx
+++ b/svx/source/accessibility/GraphCtlAccessibleContext.cxx
@@ -27,6 +27,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <tools/gen.hxx>
#include <svtools/colorcfg.hxx>
@@ -288,7 +289,7 @@ SdrObject* SvxGraphCtrlAccessibleContext::getSdrObject( sal_Int32 nIndex )
if( nullptr == mpPage )
throw DisposedException();
- if( (nIndex < 0) || ( static_cast<size_t>(nIndex) >= mpPage->GetObjCount() ) )
+ if( (nIndex < 0) || ( o3tl::make_unsigned(nIndex) >= mpPage->GetObjCount() ) )
throw lang::IndexOutOfBoundsException();
return mpPage->GetObj( nIndex );
diff --git a/svx/source/dialog/frmsel.cxx b/svx/source/dialog/frmsel.cxx
index 07cb2e0223bc..b4d80e2f759d 100644
--- a/svx/source/dialog/frmsel.cxx
+++ b/svx/source/dialog/frmsel.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <svx/frmsel.hxx>
#include <vcl/event.hxx>
#include <sal/log.hxx>
@@ -49,7 +52,7 @@ using namespace ::com::sun::star::accessibility;
FrameBorderType GetFrameBorderTypeFromIndex( size_t nIndex )
{
- DBG_ASSERT( nIndex < size_t(FRAMEBORDERTYPE_COUNT),
+ DBG_ASSERT( nIndex < o3tl::make_unsigned(FRAMEBORDERTYPE_COUNT),
"svx::GetFrameBorderTypeFromIndex - invalid index" );
return static_cast< FrameBorderType >( nIndex + 1 );
}
diff --git a/svx/source/form/filtnav.cxx b/svx/source/form/filtnav.cxx
index 9f9bf53d4e46..bf8f215f6404 100644
--- a/svx/source/form/filtnav.cxx
+++ b/svx/source/form/filtnav.cxx
@@ -40,6 +40,7 @@
#include <i18nlangtag/languagetag.hxx>
#include <fmservs.hxx>
#include <fmshimp.hxx>
+#include <o3tl/safeint.hxx>
#include <sfx2/dispatch.hxx>
#include <sfx2/objitem.hxx>
#include <sfx2/objsh.hxx>
@@ -420,7 +421,7 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermRemoved( const FilterEvent& Event
return;
auto& rTermItems = pFormItem->GetChildren();
- const bool bValidIndex = ( Event.DisjunctiveTerm >= 0 ) && ( static_cast<size_t>(Event.DisjunctiveTerm) < rTermItems.size() );
+ const bool bValidIndex = ( Event.DisjunctiveTerm >= 0 ) && ( o3tl::make_unsigned(Event.DisjunctiveTerm) < rTermItems.size() );
OSL_ENSURE( bValidIndex, "FmFilterAdapter::disjunctiveTermRemoved: invalid term index!" );
if ( !bValidIndex )
return;
@@ -455,7 +456,7 @@ void SAL_CALL FmFilterAdapter::disjunctiveTermAdded( const FilterEvent& Event )
return;
const sal_Int32 nInsertPos = Event.DisjunctiveTerm;
- bool bValidIndex = ( nInsertPos >= 0 ) && ( static_cast<size_t>(nInsertPos) <= pFormItem->GetChildren().size() );
+ bool bValidIndex = ( nInsertPos >= 0 ) && ( o3tl::make_unsigned(nInsertPos) <= pFormItem->GetChildren().size() );
if ( !bValidIndex )
{
OSL_FAIL( "FmFilterAdapter::disjunctiveTermAdded: invalid index!" );
@@ -657,7 +658,7 @@ void FmFilterModel::SetCurrentController(const Reference< XFormController > & xC
{
Reference< XFilterController > xFilterController( m_xController, UNO_QUERY_THROW );
const sal_Int32 nActiveTerm( xFilterController->getActiveTerm() );
- if ( pItem->GetChildren().size() > static_cast<size_t>(nActiveTerm) )
+ if ( pItem->GetChildren().size() > o3tl::make_unsigned(nActiveTerm) )
{
SetCurrentItems( static_cast< FmFilterItems* >( pItem->GetChildren()[ nActiveTerm ].get() ) );
}
diff --git a/svx/source/form/fmshimp.cxx b/svx/source/form/fmshimp.cxx
index b2e2104db820..8a8cf4a97484 100644
--- a/svx/source/form/fmshimp.cxx
+++ b/svx/source/form/fmshimp.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <sal/macros.h>
#include <sal/log.hxx>
#include <fmobj.hxx>
@@ -2198,7 +2200,7 @@ IMPL_LINK(FmXFormShell, OnFoundData_Lock, FmFoundRecordInformation&, rfriWhere,
LoopGrids_Lock(LoopGridsSync::FORCE_SYNC);
// and to the field (for that, I collected the XVclComponent interfaces before the start of the search)
- SAL_WARN_IF(static_cast<size_t>(rfriWhere.nFieldPos) >=
+ SAL_WARN_IF(o3tl::make_unsigned(rfriWhere.nFieldPos) >=
m_arrSearchedControls.size(),
"svx.form", "FmXFormShell::OnFoundData : invalid index!");
SdrObject* pObject = m_arrSearchedControls.at(rfriWhere.nFieldPos);
diff --git a/svx/source/form/fmsrcimp.cxx b/svx/source/form/fmsrcimp.cxx
index ffec88e8706a..5031cf2a2fba 100644
--- a/svx/source/form/fmsrcimp.cxx
+++ b/svx/source/form/fmsrcimp.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <rtl/strbuf.hxx>
#include <sal/log.hxx>
#include <svx/fmtools.hxx>
@@ -281,7 +283,7 @@ void FmSearchEngine::BuildAndInsertFieldInfo(const Reference< css::container::XI
OUString FmSearchEngine::FormatField(sal_Int32 nWhich)
{
- DBG_ASSERT(static_cast<sal_uInt32>(nWhich) < m_aControlTexts.size(), "FmSearchEngine::FormatField(sal_Int32) : invalid position !");
+ DBG_ASSERT(o3tl::make_unsigned(nWhich) < m_aControlTexts.size(), "FmSearchEngine::FormatField(sal_Int32) : invalid position !");
DBG_ASSERT(m_aControlTexts[nWhich], "FmSearchEngine::FormatField(sal_Int32) : invalid object in array !");
DBG_ASSERT(m_aControlTexts[nWhich]->getControl().is(), "FmSearchEngine::FormatField : invalid control !");
@@ -292,7 +294,7 @@ OUString FmSearchEngine::FormatField(sal_Int32 nWhich)
nWhich = m_nCurrentFieldIndex;
}
- DBG_ASSERT((nWhich >= 0) && (static_cast<sal_uInt32>(nWhich) < m_aControlTexts.size()),
+ DBG_ASSERT((nWhich >= 0) && (o3tl::make_unsigned(nWhich) < m_aControlTexts.size()),
"FmSearchEngine::FormatField : invalid argument nWhich !");
return m_aControlTexts[m_nCurrentFieldIndex == -1 ? nWhich : m_nCurrentFieldIndex]->getCurrentText();
}
@@ -1038,7 +1040,7 @@ void FmSearchEngine::RebuildUsedFields(sal_Int32 nFieldIndex, bool bForce)
DBG_ASSERT((nFieldIndex == -1) ||
((nFieldIndex >= 0) &&
- (static_cast<size_t>(nFieldIndex) < m_arrFieldMapping.size())),
+ (o3tl::make_unsigned(nFieldIndex) < m_arrFieldMapping.size())),
"FmSearchEngine::RebuildUsedFields : nFieldIndex is invalid!");
// collect all fields I need to search through
m_arrUsedFields.clear();
diff --git a/svx/source/form/formcontroller.cxx b/svx/source/form/formcontroller.cxx
index 394377122286..891df87d305f 100644
--- a/svx/source/form/formcontroller.cxx
+++ b/svx/source/form/formcontroller.cxx
@@ -87,6 +87,7 @@
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <vcl/window.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <sal/log.hxx>
@@ -745,10 +746,10 @@ void FormController::impl_setTextOnAllFilter_throw()
return;
// set the text for all filters
- OSL_ENSURE( m_aFilterRows.size() > static_cast<size_t>(m_nCurrentFilterPosition),
+ OSL_ENSURE( m_aFilterRows.size() > o3tl::make_unsigned(m_nCurrentFilterPosition),
"FormController::impl_setTextOnAllFilter_throw: m_nCurrentFilterPosition too big" );
- if ( static_cast<size_t>(m_nCurrentFilterPosition) < m_aFilterRows.size() )
+ if ( o3tl::make_unsigned(m_nCurrentFilterPosition) < m_aFilterRows.size() )
{
FmFilterRow& rRow = m_aFilterRows[ m_nCurrentFilterPosition ];
for (const auto& rEntry : rRow)
@@ -1437,7 +1438,7 @@ void SAL_CALL FormController::textChanged(const TextEvent& e)
appendEmptyDisjunctiveTerm();
// find the current row
- if ( ( static_cast<size_t>(m_nCurrentFilterPosition) >= m_aFilterRows.size() ) || ( m_nCurrentFilterPosition < 0 ) )
+ if ( ( m_nCurrentFilterPosition < 0 ) || ( o3tl::make_unsigned(m_nCurrentFilterPosition) >= m_aFilterRows.size() ) )
{
OSL_ENSURE( false, "FormController::textChanged: m_nCurrentFilterPosition is wrong!" );
return;
diff --git a/svx/source/form/navigatortreemodel.cxx b/svx/source/form/navigatortreemodel.cxx
index c58c79f1e3a3..12589592697e 100644
--- a/svx/source/form/navigatortreemodel.cxx
+++ b/svx/source/form/navigatortreemodel.cxx
@@ -33,6 +33,7 @@
#include <svx/strings.hrc>
#include <fmshimp.hxx>
#include <fmobj.hxx>
+#include <o3tl/safeint.hxx>
#include <sfx2/objsh.hxx>
#include <tools/diagnose_ex.h>
#include <com/sun/star/container/XContainer.hpp>
@@ -281,7 +282,7 @@ namespace svxform
m_pFormModel->BegUndo(aUndoStr);
}
- if (nRelPos >= static_cast<sal_uInt32>(xContainer->getCount()))
+ if (nRelPos >= o3tl::make_unsigned(xContainer->getCount()))
nRelPos = static_cast<sal_uInt32>(xContainer->getCount());
// UndoAction
diff --git a/svx/source/items/numfmtsh.cxx b/svx/source/items/numfmtsh.cxx
index f950eb0afd86..3a329b7181a4 100644
--- a/svx/source/items/numfmtsh.cxx
+++ b/svx/source/items/numfmtsh.cxx
@@ -21,7 +21,7 @@
#include <tools/debug.hxx>
#include <i18nlangtag/mslangid.hxx>
-
+#include <o3tl/safeint.hxx>
#include <svl/zforlist.hxx>
#include <svl/zformat.hxx>
#include <svl/currencytable.hxx>
@@ -1228,7 +1228,7 @@ OUString SvxNumberFormatShell::GetComment4Entry(short nEntry)
if (nEntry < 0)
return OUString();
- if (static_cast<size_t>(nEntry) < aCurEntryList.size())
+ if (o3tl::make_unsigned(nEntry) < aCurEntryList.size())
{
sal_uInt32 nMyNfEntry = aCurEntryList[nEntry];
const SvNumberformat* pNumEntry = pFormatter->GetEntry(nMyNfEntry);
@@ -1248,7 +1248,7 @@ short SvxNumberFormatShell::GetCategory4Entry(short nEntry) const
{
if (nEntry < 0)
return 0;
- if (static_cast<size_t>(nEntry) < aCurEntryList.size())
+ if (o3tl::make_unsigned(nEntry) < aCurEntryList.size())
{
sal_uInt32 nMyNfEntry = aCurEntryList[nEntry];
@@ -1282,7 +1282,7 @@ bool SvxNumberFormatShell::GetUserDefined4Entry(short nEntry)
{
if (nEntry < 0)
return false;
- if (static_cast<size_t>(nEntry) < aCurEntryList.size())
+ if (o3tl::make_unsigned(nEntry) < aCurEntryList.size())
{
sal_uInt32 nMyNfEntry = aCurEntryList[nEntry];
const SvNumberformat* pNumEntry = pFormatter->GetEntry(nMyNfEntry);
@@ -1310,7 +1310,7 @@ OUString SvxNumberFormatShell::GetFormat4Entry(short nEntry)
if (!aCurrencyFormatList.empty())
{
- if (aCurrencyFormatList.size() > static_cast<size_t>(nEntry))
+ if (aCurrencyFormatList.size() > o3tl::make_unsigned(nEntry))
return aCurrencyFormatList[nEntry];
}
else
@@ -1335,7 +1335,7 @@ short SvxNumberFormatShell::GetListPos4Entry( sal_uInt32 nIdx, const OUString& r
if (nIdx != NUMBERFORMAT_ENTRY_NEW_CURRENCY)
{
// Check list size against return type limit.
- if (aCurEntryList.size() <= static_cast<size_t>(::std::numeric_limits<short>::max()))
+ if (aCurEntryList.size() <= o3tl::make_unsigned(::std::numeric_limits<short>::max()))
{
for (size_t i = 0; i < aCurEntryList.size(); ++i)
{
diff --git a/svx/source/svdraw/svdotextpathdecomposition.cxx b/svx/source/svdraw/svdotextpathdecomposition.cxx
index 98836adc92e5..9b1cce14f361 100644
--- a/svx/source/svdraw/svdotextpathdecomposition.cxx
+++ b/svx/source/svdraw/svdotextpathdecomposition.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <svx/svdotext.hxx>
#include <svx/svdoutl.hxx>
#include <basegfx/vector/b2dvector.hxx>
@@ -695,7 +697,7 @@ void SdrTextObj::impDecomposePathTextPrimitive(
// get loop count
sal_uInt32 nLoopCount(rPathPolyPolygon.count());
- if(static_cast<sal_uInt32>(rOutliner.GetParagraphCount()) < nLoopCount)
+ if(o3tl::make_unsigned(rOutliner.GetParagraphCount()) < nLoopCount)
{
nLoopCount = rOutliner.GetParagraphCount();
}
diff --git a/svx/source/svdraw/svdpage.cxx b/svx/source/svdraw/svdpage.cxx
index 8012cf7258d2..5ffb31cf0d13 100644
--- a/svx/source/svdraw/svdpage.cxx
+++ b/svx/source/svdraw/svdpage.cxx
@@ -23,6 +23,7 @@
#include <svx/svdpage.hxx>
+#include <o3tl/safeint.hxx>
#include <sot/storage.hxx>
#include <comphelper/classids.hxx>
#include <svx/svdview.hxx>
@@ -589,7 +590,7 @@ void SdrObjList::sort( std::vector<sal_Int32>& sortOrder)
{
// no negative indexes and indexes larger than maList size are allowed
auto it = std::find_if( sortOrder.begin(), sortOrder.end(), [this](const sal_Int32& rIt)
- { return ( rIt < 0 || static_cast<size_t>(rIt) >= maList.size() ); } );
+ { return ( rIt < 0 || o3tl::make_unsigned(rIt) >= maList.size() ); } );
if ( it != sortOrder.end())
throw css::lang::IllegalArgumentException("negative index of shape", nullptr, 1);
diff --git a/svx/source/tbxctrls/tbcontrl.cxx b/svx/source/tbxctrls/tbcontrl.cxx
index 7aee71bb5d81..4421e0f7d3b8 100644
--- a/svx/source/tbxctrls/tbcontrl.cxx
+++ b/svx/source/tbxctrls/tbcontrl.cxx
@@ -112,6 +112,7 @@
#include <cppu/unotype.hxx>
#include <cppuhelper/supportsservice.hxx>
#include <officecfg/Office/Common.hxx>
+#include <o3tl/safeint.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <bitmaps.hlst>
#include <sal/log.hxx>
@@ -534,7 +535,7 @@ private:
SvxBorderLineStyle LineListBox::GetEntryStyle( sal_Int32 nPos ) const
{
- ImpLineListData* pData = (0 <= nPos && static_cast<size_t>(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr;
+ ImpLineListData* pData = (0 <= nPos && o3tl::make_unsigned(nPos) < m_vLineList.size()) ? m_vLineList[ nPos ].get() : nullptr;
return pData ? pData->GetStyle() : SvxBorderLineStyle::NONE;
}
diff --git a/svx/source/unodraw/unopage.cxx b/svx/source/unodraw/unopage.cxx
index 28082f35e75f..75522fc5e27a 100644
--- a/svx/source/unodraw/unopage.cxx
+++ b/svx/source/unodraw/unopage.cxx
@@ -24,6 +24,7 @@
#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <com/sun/star/lang/DisposedException.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <sfx2/dispatch.hxx>
#include <comphelper/classids.hxx>
@@ -355,7 +356,7 @@ uno::Any SAL_CALL SvxDrawPage::getByIndex( sal_Int32 Index )
if( (mpModel == nullptr) || (mpPage == nullptr) )
throw lang::DisposedException("Model or Page was already disposed!");
- if ( Index < 0 || static_cast<size_t>(Index) >= mpPage->GetObjCount() )
+ if ( Index < 0 || o3tl::make_unsigned(Index) >= mpPage->GetObjCount() )
throw lang::IndexOutOfBoundsException("Index (" + OUString::number(Index)
+ ") needs to be a positive integer smaller than the shape count ("
+ OUString::number(mpPage->GetObjCount()) + ")!");
diff --git a/svx/source/unodraw/unoshap2.cxx b/svx/source/unodraw/unoshap2.cxx
index 4c3a1bcbd963..d7dbfd9a0a69 100644
--- a/svx/source/unodraw/unoshap2.cxx
+++ b/svx/source/unodraw/unoshap2.cxx
@@ -33,6 +33,7 @@
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/drawing/QRCode.hpp>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/urlobj.hxx>
#include <vcl/svapp.hxx>
#include <osl/file.hxx>
@@ -324,7 +325,7 @@ uno::Any SAL_CALL SvxShapeGroup::getByIndex( sal_Int32 Index )
if( !HasSdrObject() || GetSdrObject()->GetSubList() == nullptr )
throw uno::RuntimeException();
- if( Index<0 || GetSdrObject()->GetSubList()->GetObjCount() <= static_cast<size_t>(Index) )
+ if( Index<0 || GetSdrObject()->GetSubList()->GetObjCount() <= o3tl::make_unsigned(Index) )
throw lang::IndexOutOfBoundsException();
SdrObject* pDestObj = GetSdrObject()->GetSubList()->GetObj( Index );
diff --git a/svx/source/unodraw/unoshap3.cxx b/svx/source/unodraw/unoshap3.cxx
index aaa66de99511..8c29b05755b2 100644
--- a/svx/source/unodraw/unoshap3.cxx
+++ b/svx/source/unodraw/unoshap3.cxx
@@ -27,6 +27,7 @@
#include <com/sun/star/drawing/DoubleSequence.hpp>
#include <com/sun/star/drawing/CameraGeometry.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <comphelper/sequence.hxx>
#include <sal/log.hxx>
@@ -199,7 +200,7 @@ uno::Any SAL_CALL Svx3DSceneObject::getByIndex( sal_Int32 Index )
if( !HasSdrObject() || GetSdrObject()->GetSubList() == nullptr )
throw uno::RuntimeException();
- if( Index<0 || GetSdrObject()->GetSubList()->GetObjCount() <= static_cast<size_t>(Index) )
+ if( Index<0 || GetSdrObject()->GetSubList()->GetObjCount() <= o3tl::make_unsigned(Index) )
throw lang::IndexOutOfBoundsException();
SdrObject* pDestObj = GetSdrObject()->GetSubList()->GetObj( Index );
diff --git a/svx/source/xoutdev/xtable.cxx b/svx/source/xoutdev/xtable.cxx
index a4ae1c9a368b..f9dad9e532c5 100644
--- a/svx/source/xoutdev/xtable.cxx
+++ b/svx/source/xoutdev/xtable.cxx
@@ -21,6 +21,7 @@
#include <svx/XPropertyTable.hxx>
#include <xmlxtexp.hxx>
#include <xmlxtimp.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/urlobj.hxx>
#include <svx/xtable.hxx>
#include <svx/xpool.hxx>
@@ -113,7 +114,7 @@ XPropertyList::XPropertyList(
bool XPropertyList::isValidIdx(long nIndex) const
{
- return (static_cast<size_t>(nIndex) < maList.size() && nIndex >= 0);
+ return (nIndex >= 0 && o3tl::make_unsigned(nIndex) < maList.size());
}
diff --git a/sw/qa/extras/globalfilter/globalfilter.cxx b/sw/qa/extras/globalfilter/globalfilter.cxx
index f0d61355ea86..4ec7563ff324 100644
--- a/sw/qa/extras/globalfilter/globalfilter.cxx
+++ b/sw/qa/extras/globalfilter/globalfilter.cxx
@@ -12,6 +12,7 @@
#include <com/sun/star/awt/XBitmap.hpp>
#include <com/sun/star/graphic/XGraphic.hpp>
#include <com/sun/star/graphic/GraphicType.hpp>
+#include <o3tl/safeint.hxx>
#include <officecfg/Office/Common.hxx>
#include <sfx2/linkmgr.hxx>
#include <comphelper/propertysequence.hxx>
@@ -1056,7 +1057,7 @@ void Test::testBulletAsImage()
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
Graphic aGraphic(uno::Reference<graphic::XGraphic>(xBitmap, uno::UNO_QUERY));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), GraphicType::Bitmap, aGraphic.GetType());
- CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), aGraphic.GetSizeBytes() > sal_uLong(0));
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), aGraphic.GetSizeBytes() > o3tl::make_unsigned(0));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 16L, aGraphic.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 16L, aGraphic.GetSizePixel().Height());
@@ -1116,7 +1117,7 @@ void Test::testBulletAsImage()
CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), xBitmap.is());
Graphic aGraphic(uno::Reference<graphic::XGraphic>(xBitmap, uno::UNO_QUERY));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), GraphicType::Bitmap, aGraphic.GetType());
- CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), aGraphic.GetSizeBytes() > sal_uLong(0));
+ CPPUNIT_ASSERT_MESSAGE(sFailedMessage.getStr(), aGraphic.GetSizeBytes() > o3tl::make_unsigned(0));
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 16L, aGraphic.GetSizePixel().Width());
CPPUNIT_ASSERT_EQUAL_MESSAGE(sFailedMessage.getStr(), 16L, aGraphic.GetSizePixel().Height());
diff --git a/sw/source/core/access/accselectionhelper.cxx b/sw/source/core/access/accselectionhelper.cxx
index 8b1416b9d576..be92d4a2c5aa 100644
--- a/sw/source/core/access/accselectionhelper.cxx
+++ b/sw/source/core/access/accselectionhelper.cxx
@@ -22,6 +22,7 @@
#include "acccontext.hxx"
#include <accmap.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/AccessibleShape.hxx>
#include <viewsh.hxx>
#include <fesh.hxx>
@@ -225,7 +226,7 @@ sal_Int32 SwAccessibleSelectionHelper::getSelectedAccessibleChildCount( )
{
nCount++;
}
- if (static_cast<size_t>(nCount) >= nSelObjs)
+ if (o3tl::make_unsigned(nCount) >= nSelObjs)
break;
}
}
@@ -284,7 +285,7 @@ Reference<XAccessible> SwAccessibleSelectionHelper::getSelectedAccessibleChild(
else
{
const size_t nSelObjs = pFEShell->IsObjSelected();
- if( 0 == nSelObjs || static_cast<size_t>(nSelectedChildIndex) >= nSelObjs )
+ if( 0 == nSelObjs || o3tl::make_unsigned(nSelectedChildIndex) >= nSelObjs )
throwIndexOutOfBoundsException();
std::list< SwAccessibleChild > aChildren;
diff --git a/sw/source/core/access/acctable.cxx b/sw/source/core/access/acctable.cxx
index 0a2fc87c75f8..d3cf02d8291a 100644
--- a/sw/source/core/access/acctable.cxx
+++ b/sw/source/core/access/acctable.cxx
@@ -27,6 +27,7 @@
#include <com/sun/star/accessibility/AccessibleTableModelChange.hpp>
#include <com/sun/star/accessibility/AccessibleTableModelChangeType.hpp>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <o3tl/safeint.hxx>
#include <unotools/accessiblestatesethelper.hxx>
#include <vcl/svapp.hxx>
#include <frmfmt.hxx>
@@ -488,9 +489,9 @@ uno::Sequence < sal_Int32 > SwAccAllTableSelHander_Impl::GetSelSequence()
void SwAccAllTableSelHander_Impl::Unselect( sal_Int32 nRowOrCol,
sal_Int32 nExt )
{
- OSL_ENSURE( static_cast< size_t >( nRowOrCol ) < m_aSelected.size(),
+ OSL_ENSURE( o3tl::make_unsigned( nRowOrCol ) < m_aSelected.size(),
"index too large" );
- OSL_ENSURE( static_cast< size_t >( nRowOrCol+nExt ) <= m_aSelected.size(),
+ OSL_ENSURE( o3tl::make_unsigned( nRowOrCol+nExt ) <= m_aSelected.size(),
"extent too large" );
while( nExt )
{
diff --git a/sw/source/core/crsr/findtxt.cxx b/sw/source/core/crsr/findtxt.cxx
index 729fef65c063..ec1dc65d63a6 100644
--- a/sw/source/core/crsr/findtxt.cxx
+++ b/sw/source/core/crsr/findtxt.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/util/SearchFlags.hpp>
#include <com/sun/star/util/SearchResult.hpp>
#include <comphelper/lok.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/svdview.hxx>
#include <svl/srchitem.hxx>
#include <sfx2/sfxsids.hrc>
@@ -620,7 +621,7 @@ bool FindTextImpl(SwPaM & rSearchPam,
AmbiguousIndex nEndInside;
sal_Int32 aLoop = bSrchForward ? 0 : postits.size();
- while ((0 <= aLoop) && (static_cast<size_t>(aLoop) <= postits.size()))
+ while ((0 <= aLoop) && (o3tl::make_unsigned(aLoop) <= postits.size()))
{
if (bSrchForward)
{
diff --git a/sw/source/core/doc/DocumentContentOperationsManager.cxx b/sw/source/core/doc/DocumentContentOperationsManager.cxx
index 7c880c26ff68..4a412897da24 100644
--- a/sw/source/core/doc/DocumentContentOperationsManager.cxx
+++ b/sw/source/core/doc/DocumentContentOperationsManager.cxx
@@ -66,6 +66,7 @@
#include <hints.hxx>
#include <fmtflcnt.hxx>
#include <docedt.hxx>
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <unotools/charclass.hxx>
#include <unotools/configmgr.hxx>
@@ -668,7 +669,7 @@ namespace
{
const sal_uInt64 nSum = pStt->nContent.GetIndex() +
pEndNd->GetText().getLength() - pEnd->nContent.GetIndex();
- return nSum > static_cast<sal_uInt64>(SAL_MAX_INT32);
+ return nSum > o3tl::make_unsigned(SAL_MAX_INT32);
}
}
return false;
diff --git a/sw/source/core/doc/doccomp.cxx b/sw/source/core/doc/doccomp.cxx
index cc58624de54c..4576e7077760 100644
--- a/sw/source/core/doc/doccomp.cxx
+++ b/sw/source/core/doc/doccomp.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/character.hxx>
#include <swmodule.hxx>
@@ -878,7 +881,7 @@ sal_uLong Compare::CompareSequence::CheckDiag( sal_uLong nStt1, sal_uLong nEnd1,
else
x = thi;
y = x - d;
- while( sal_uLong(x) < nEnd1 && sal_uLong(y) < nEnd2 &&
+ while( o3tl::make_unsigned(x) < nEnd1 && o3tl::make_unsigned(y) < nEnd2 &&
rMoved1.GetIndex( x ) == rMoved2.GetIndex( y ))
{
++x;
@@ -910,7 +913,7 @@ sal_uLong Compare::CompareSequence::CheckDiag( sal_uLong nStt1, sal_uLong nEnd1,
else
x = thi - 1;
y = x - d;
- while( sal_uLong(x) > nStt1 && sal_uLong(y) > nStt2 &&
+ while( o3tl::make_unsigned(x) > nStt1 && o3tl::make_unsigned(y) > nStt2 &&
rMoved1.GetIndex( x - 1 ) == rMoved2.GetIndex( y - 1 ))
{
--x;
diff --git a/sw/source/core/doc/docnum.cxx b/sw/source/core/doc/docnum.cxx
index f28a1562a8af..f4f83dcd56ab 100644
--- a/sw/source/core/doc/docnum.cxx
+++ b/sw/source/core/doc/docnum.cxx
@@ -48,6 +48,7 @@
#include <calbck.hxx>
#include <comphelper/string.hxx>
#include <comphelper/random.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/datetimeutils.hxx>
#include <map>
@@ -518,7 +519,7 @@ bool SwDoc::MoveOutlinePara( const SwPaM& rPam, SwOutlineNodes::difference_type
++aEndRg;
// calculation of the new position
- if( nOffset < 0 && nCurrentPos < SwOutlineNodes::size_type(-nOffset) )
+ if( nOffset < 0 && nCurrentPos < o3tl::make_unsigned(-nOffset) )
pNd = GetNodes().GetEndOfContent().StartOfSectionNode();
else if( nCurrentPos + nOffset >= GetNodes().GetOutLineNds().size() )
pNd = &GetNodes().GetEndOfContent();
@@ -1987,7 +1988,7 @@ bool SwDoc::MoveParagraphImpl(SwPaM& rPam, long const nOffset,
else
{
// Impossible to move to negative index
- if( sal_uLong(std::abs( nOffset )) > nStIdx)
+ if( o3tl::make_unsigned(std::abs( nOffset )) > nStIdx)
return false;
nInEndIdx = nStIdx - 1;
diff --git a/sw/source/core/edit/edglss.cxx b/sw/source/core/edit/edglss.cxx
index 7d691913435a..b35c45a6fcf2 100644
--- a/sw/source/core/edit/edglss.cxx
+++ b/sw/source/core/edit/edglss.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <tools/urlobj.hxx>
#include <doc.hxx>
@@ -311,7 +314,7 @@ void SwEditShell::GetSelectedText( OUString &rBuf, ParaBreakType nHndlParaBrk )
else
{
const sal_uInt64 nLen = aStream.GetSize();
- OSL_ENSURE( nLen/sizeof( sal_Unicode )<static_cast<sal_uInt64>(SAL_MAX_INT32), "Stream can't fit in OUString" );
+ OSL_ENSURE( nLen/sizeof( sal_Unicode )<o3tl::make_unsigned(SAL_MAX_INT32), "Stream can't fit in OUString" );
rtl_uString *pStr = rtl_uString_alloc(static_cast<sal_Int32>(nLen / sizeof( sal_Unicode )));
aStream.Seek( 0 );
aStream.ResetError();
diff --git a/sw/source/core/fields/cellfml.cxx b/sw/source/core/fields/cellfml.cxx
index c4232accddfa..e7e3830f6983 100644
--- a/sw/source/core/fields/cellfml.cxx
+++ b/sw/source/core/fields/cellfml.cxx
@@ -44,6 +44,7 @@
#include <cellatr.hxx>
#include <ndindex.hxx>
#include <comphelper/string.hxx>
+#include <o3tl/safeint.hxx>
namespace
{
@@ -796,14 +797,14 @@ static const SwTableBox* lcl_RelToBox( const SwTable& rTable,
nLineOffset < 0 )
return nullptr;
- if( static_cast<size_t>(nLineOffset) >= pLines->size() )
+ if( o3tl::make_unsigned(nLineOffset) >= pLines->size() )
return nullptr;
pLine = (*pLines)[ nLineOffset ];
// ... then search the box
pBoxes = &pLine->GetTabBoxes();
- if( static_cast<size_t>(nBoxOffset) >= pBoxes->size() )
+ if( o3tl::make_unsigned(nBoxOffset) >= pBoxes->size() )
return nullptr;
pBox = (*pBoxes)[ nBoxOffset ];
diff --git a/sw/source/core/text/itradj.cxx b/sw/source/core/text/itradj.cxx
index 6c511f63f429..b1b712db4274 100644
--- a/sw/source/core/text/itradj.cxx
+++ b/sw/source/core/text/itradj.cxx
@@ -17,6 +17,10 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
+
#include <IDocumentSettingAccess.hxx>
#include <doc.hxx>
@@ -127,7 +131,7 @@ static bool lcl_CheckKashidaPositions( SwScriptInfo& rSI, SwTextSizeInfo& rInf,
// if two characters are replaced by a ligature glyph, there will be no place for a kashida
std::vector<TextFrameIndex> aKashidaPos;
rSI.GetKashidaPositions(nIdx, rItr.GetLength(), aKashidaPos);
- assert(aKashidaPos.size() >= static_cast<size_t>(rKashidas));
+ assert(aKashidaPos.size() >= o3tl::make_unsigned(rKashidas));
std::vector<TextFrameIndex> aKashidaPosDropped(aKashidaPos.size());
sal_Int32 nKashidaIdx = 0;
while ( rKashidas && nIdx < nEnd )
diff --git a/sw/source/core/text/redlnitr.cxx b/sw/source/core/text/redlnitr.cxx
index 39868efa72d3..6d3881533ac0 100644
--- a/sw/source/core/text/redlnitr.cxx
+++ b/sw/source/core/text/redlnitr.cxx
@@ -22,6 +22,7 @@
#include <string_view>
#include <hintids.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/whiter.hxx>
#include <com/sun/star/i18n/ScriptType.hpp>
#include <scriptinfo.hxx>
@@ -911,7 +912,7 @@ sal_Int32 SwExtend::Next(sal_uLong const nNode, sal_Int32 nNext)
{
sal_Int32 nIdx = m_nPos - m_nStart;
const ExtTextInputAttr nAttr = m_rArr[ nIdx ];
- while (static_cast<size_t>(++nIdx) < m_rArr.size() && nAttr == m_rArr[nIdx])
+ while (o3tl::make_unsigned(++nIdx) < m_rArr.size() && nAttr == m_rArr[nIdx])
; //nothing
nIdx = nIdx + m_nStart;
if( nNext > nIdx )
diff --git a/sw/source/core/tox/ToxWhitespaceStripper.cxx b/sw/source/core/tox/ToxWhitespaceStripper.cxx
index fc51a94c2e33..b2fe68727714 100644
--- a/sw/source/core/tox/ToxWhitespaceStripper.cxx
+++ b/sw/source/core/tox/ToxWhitespaceStripper.cxx
@@ -9,6 +9,7 @@
#include <ToxWhitespaceStripper.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -49,7 +50,7 @@ sal_Int32
ToxWhitespaceStripper::GetPositionInStrippedString(sal_Int32 pos) const
{
assert(0 <= pos);
- if (static_cast<size_t>(pos) >= mNewPositions.size()) {
+ if (o3tl::make_unsigned(pos) >= mNewPositions.size()) {
// TODO probably this should assert, not just warn?
SAL_WARN("sw.core", "Requested position of TOX entry text which does not exist. "
"Maybe the formatting hint is corrupt?");
diff --git a/sw/source/core/txtnode/txtedt.cxx b/sw/source/core/txtnode/txtedt.cxx
index 54af3640e13b..e7f6a326dae2 100644
--- a/sw/source/core/txtnode/txtedt.cxx
+++ b/sw/source/core/txtnode/txtedt.cxx
@@ -27,6 +27,7 @@
#include <editeng/hangulhanja.hxx>
#include <i18nutil/transliteration.hxx>
#include <SwSmartTagMgr.hxx>
+#include <o3tl/safeint.hxx>
#include <officecfg/Office/Writer.hxx>
#include <unotools/transliterationwrapper.hxx>
#include <unotools/charclass.hxx>
@@ -1904,7 +1905,7 @@ void SwTextNode::TransliterateText(
swTransliterationChgData & rData =
aChanges[ aChanges.size() - 1 - i ];
nSum += rData.sChanged.getLength() - rData.nLen;
- if (nSum > static_cast<size_t>(GetSpaceLeft()))
+ if (nSum > o3tl::make_unsigned(GetSpaceLeft()))
{
SAL_WARN("sw.core", "SwTextNode::ReplaceTextOnly: "
"node text with insertion > node capacity.");
diff --git a/sw/source/core/unocore/unocoll.cxx b/sw/source/core/unocore/unocoll.cxx
index bf8ea87af1e4..a0f972f85628 100644
--- a/sw/source/core/unocore/unocoll.cxx
+++ b/sw/source/core/unocore/unocoll.cxx
@@ -32,6 +32,7 @@
#include <fmtftn.hxx>
#include <txtftn.hxx>
#include <com/sun/star/text/XTextTable.hpp>
+#include <o3tl/safeint.hxx>
#include <svtools/unoimap.hxx>
#include <svtools/unoevent.hxx>
#include <unotbl.hxx>
@@ -1410,7 +1411,7 @@ uno::Any SwXTextSections::getByIndex(sal_Int32 nIndex)
if(static_cast<size_t>(nIndex) == i)
break;
}
- if(!(nIndex >= 0 && static_cast<size_t>(nIndex) < rFormats.size()))
+ if(!(nIndex >= 0 && o3tl::make_unsigned(nIndex) < rFormats.size()))
throw IndexOutOfBoundsException();
SwSectionFormat* pFormat = rFormats[nIndex];
@@ -1699,7 +1700,7 @@ uno::Any SwXNumberingRulesCollection::getByIndex(sal_Int32 nIndex)
throw uno::RuntimeException();
uno::Reference< XIndexReplace > xRef;
- if ( static_cast<size_t>(nIndex) < GetDoc()->GetNumRuleTable().size() )
+ if ( o3tl::make_unsigned(nIndex) < GetDoc()->GetNumRuleTable().size() )
{
xRef = new SwXNumberingRules( *GetDoc()->GetNumRuleTable()[ nIndex ], GetDoc());
aRet <<= xRef;
diff --git a/sw/source/core/unocore/unofield.cxx b/sw/source/core/unocore/unofield.cxx
index 4254b3fa42c6..0067dff27216 100644
--- a/sw/source/core/unocore/unofield.cxx
+++ b/sw/source/core/unocore/unofield.cxx
@@ -79,6 +79,7 @@
#include <svl/listener.hxx>
#include <svx/dataaccessdescriptor.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <vcl/svapp.hxx>
#include <textapi.hxx>
@@ -1029,7 +1030,7 @@ OUString SwXFieldMaster::GetProgrammaticName(const SwFieldType& rType, SwDoc& rD
if(SwFieldIds::SetExp == rType.Which())
{
const SwFieldTypes* pTypes = rDoc.getIDocumentFieldsAccess().GetFieldTypes();
- for( size_t i = 0; i <= size_t(INIT_FLDTYPES); i++ )
+ for( size_t i = 0; i <= o3tl::make_unsigned(INIT_FLDTYPES); i++ )
{
if((*pTypes)[i].get() == &rType)
{
diff --git a/sw/source/core/unocore/unoflatpara.cxx b/sw/source/core/unocore/unoflatpara.cxx
index 6a1546372361..15ffb4441aa7 100644
--- a/sw/source/core/unocore/unoflatpara.cxx
+++ b/sw/source/core/unocore/unoflatpara.cxx
@@ -21,6 +21,7 @@
#include <unocrsrhelper.hxx>
#include <unoflatpara.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <com/sun/star/text/TextMarkupType.hpp>
#include <com/sun/star/beans/PropertyAttribute.hpp>
@@ -250,7 +251,7 @@ void SAL_CALL SwXFlatParagraph::changeText(::sal_Int32 nPos, ::sal_Int32 nLen, c
SwTextNode *const pOldTextNode = GetTextNode();
- if (nPos < 0 || pOldTextNode->Len() < nPos || nLen < 0 || static_cast<sal_uInt32>(pOldTextNode->Len()) < static_cast<sal_uInt32>(nPos) + nLen)
+ if (nPos < 0 || pOldTextNode->Len() < nPos || nLen < 0 || o3tl::make_unsigned(pOldTextNode->Len()) < static_cast<sal_uInt32>(nPos) + nLen)
{
throw lang::IllegalArgumentException();
}
@@ -283,7 +284,7 @@ void SAL_CALL SwXFlatParagraph::changeAttributes(::sal_Int32 nPos, ::sal_Int32 n
if (!GetTextNode())
return;
- if (nPos < 0 || GetTextNode()->Len() < nPos || nLen < 0 || static_cast<sal_uInt32>(GetTextNode()->Len()) < static_cast<sal_uInt32>(nPos) + nLen)
+ if (nPos < 0 || GetTextNode()->Len() < nPos || nLen < 0 || o3tl::make_unsigned(GetTextNode()->Len()) < static_cast<sal_uInt32>(nPos) + nLen)
{
throw lang::IllegalArgumentException();
}
diff --git a/sw/source/core/unocore/unoobj.cxx b/sw/source/core/unocore/unoobj.cxx
index 612adeb01e90..ddd352386d11 100644
--- a/sw/source/core/unocore/unoobj.cxx
+++ b/sw/source/core/unocore/unoobj.cxx
@@ -22,6 +22,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <svl/itemprop.hxx>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <unotools/collatorwrapper.hxx>
#include <swtypes.hxx>
@@ -156,7 +157,7 @@ void SwUnoCursorHelper::GetTextFromPam(SwPaM & rPam, OUString & rBuffer,
if( ! aWriter.Write( xWrt ).IsError() )
{
const sal_uInt64 lUniLen = aStream.GetSize()/sizeof( sal_Unicode );
- if (lUniLen < static_cast<sal_uInt64>(SAL_MAX_INT32-1))
+ if (lUniLen < o3tl::make_unsigned(SAL_MAX_INT32-1))
{
aStream.WriteUInt16( '\0' );
diff --git a/sw/source/core/unocore/unoobj2.cxx b/sw/source/core/unocore/unoobj2.cxx
index a4708d249970..417370f05980 100644
--- a/sw/source/core/unocore/unoobj2.cxx
+++ b/sw/source/core/unocore/unoobj2.cxx
@@ -21,6 +21,7 @@
#include <comphelper/servicehelper.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/listener.hxx>
#include <svx/svdobj.hxx>
#include <vcl/svapp.hxx>
@@ -1487,7 +1488,7 @@ sal_Int32 SAL_CALL SwXTextRangesImpl::getCount()
uno::Any SAL_CALL SwXTextRangesImpl::getByIndex(sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
- if ((nIndex < 0) || (static_cast<size_t>(nIndex) >= m_Ranges.size()))
+ if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= m_Ranges.size()))
throw lang::IndexOutOfBoundsException();
uno::Any ret;
ret <<= m_Ranges.at(nIndex);
diff --git a/sw/source/core/unocore/unoredlines.cxx b/sw/source/core/unocore/unoredlines.cxx
index 9e1db2b8e637..bbab06ed6a13 100644
--- a/sw/source/core/unocore/unoredlines.cxx
+++ b/sw/source/core/unocore/unoredlines.cxx
@@ -22,6 +22,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <vcl/svapp.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <unoredlines.hxx>
@@ -59,7 +60,7 @@ uno::Any SwXRedlines::getByIndex(sal_Int32 nIndex)
if(!IsValid())
throw uno::RuntimeException();
const SwRedlineTable& rRedTable = GetDoc()->getIDocumentRedlineAccess().GetRedlineTable();
- if ((rRedTable.size() <= static_cast<size_t>(nIndex)) || (nIndex < 0))
+ if ((nIndex < 0) || (rRedTable.size() <= o3tl::make_unsigned(nIndex)))
throw lang::IndexOutOfBoundsException();
uno::Reference <beans::XPropertySet> xRet = SwXRedlines::GetObject( *rRedTable[nIndex], *GetDoc() );
diff --git a/sw/source/core/unocore/unostyle.cxx b/sw/source/core/unocore/unostyle.cxx
index 4ca49fee3864..7301c7afb8fa 100644
--- a/sw/source/core/unocore/unostyle.cxx
+++ b/sw/source/core/unocore/unostyle.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <svx/svxids.hrc>
#include <hintids.hxx>
#include <vcl/svapp.hxx>
@@ -4720,7 +4723,7 @@ SwBoxAutoFormat* SwXTextCellStyle::GetBoxAutoFormat(SwDocShell* pDocShell, const
return nullptr;
const auto& rTableTemplateMap = SwTableAutoFormat::GetTableTemplateMap();
- if (rTableTemplateMap.size() <= static_cast<size_t>(nTemplateIndex))
+ if (rTableTemplateMap.size() <= o3tl::make_unsigned(nTemplateIndex))
return nullptr;
SwTableAutoFormat* pTableAutoFormat = pDocShell->GetDoc()->GetTableStyles().FindAutoFormat(sParentName);
diff --git a/sw/source/core/unocore/unotbl.cxx b/sw/source/core/unocore/unotbl.cxx
index 73b64b806968..779b1078c528 100644
--- a/sw/source/core/unocore/unotbl.cxx
+++ b/sw/source/core/unocore/unotbl.cxx
@@ -24,6 +24,7 @@
#include <algorithm>
#include <o3tl/any.hxx>
+#include <o3tl/safeint.hxx>
#include <svx/svxids.hrc>
#include <editeng/memberids.h>
#include <float.h>
@@ -4037,7 +4038,7 @@ uno::Any SwXTableRows::getByIndex(sal_Int32 nIndex)
if(nIndex < 0)
throw lang::IndexOutOfBoundsException();
SwTable* pTable = SwTable::FindTable( pFrameFormat );
- if(static_cast<size_t>(nIndex) >= pTable->GetTabLines().size())
+ if(o3tl::make_unsigned(nIndex) >= pTable->GetTabLines().size())
throw lang::IndexOutOfBoundsException();
SwTableLine* pLine = pTable->GetTabLines()[nIndex];
FindUnoInstanceHint<SwTableLine,SwXTextTableRow> aHint{pLine};
@@ -4071,7 +4072,7 @@ void SwXTableRows::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount)
SwFrameFormat* pFrameFormat(lcl_EnsureCoreConnected(GetFrameFormat(), static_cast<cppu::OWeakObject*>(this)));
SwTable* pTable = lcl_EnsureTableNotComplex(SwTable::FindTable(pFrameFormat), static_cast<cppu::OWeakObject*>(this));
const size_t nRowCount = pTable->GetTabLines().size();
- if (nCount <= 0 || !(0 <= nIndex && static_cast<size_t>(nIndex) <= nRowCount))
+ if (nCount <= 0 || !(0 <= nIndex && o3tl::make_unsigned(nIndex) <= nRowCount))
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const OUString sTLName = sw_GetCellName(0, nIndex);
const SwTableBox* pTLBox = pTable->GetTableBox(sTLName);
@@ -4230,7 +4231,7 @@ void SwXTableColumns::insertByIndex(sal_Int32 nIndex, sal_Int32 nCount)
SwTableLines& rLines = pTable->GetTabLines();
SwTableLine* pLine = rLines.front();
const size_t nColCount = pLine->GetTabBoxes().size();
- if (nCount <= 0 || !(0 <= nIndex && static_cast<size_t>(nIndex) <= nColCount))
+ if (nCount <= 0 || !(0 <= nIndex && o3tl::make_unsigned(nIndex) <= nColCount))
throw uno::RuntimeException("Illegal arguments", static_cast<cppu::OWeakObject*>(this));
const OUString sTLName = sw_GetCellName(nIndex, 0);
const SwTableBox* pTLBox = pTable->GetTableBox( sTLName );
diff --git a/sw/source/core/unocore/unotextmarkup.cxx b/sw/source/core/unocore/unotextmarkup.cxx
index 1d4074d4462a..f20b47e15651 100644
--- a/sw/source/core/unocore/unotextmarkup.cxx
+++ b/sw/source/core/unocore/unotextmarkup.cxx
@@ -19,6 +19,7 @@
#include <unotextmarkup.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <svl/listener.hxx>
#include <vcl/svapp.hxx>
@@ -513,7 +514,7 @@ void SAL_CALL SwXStringKeyMap::insertValue(const OUString & aKey, const uno::Any
OUString SAL_CALL SwXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex)
{
- if ( static_cast<sal_uInt32>(nIndex) >= maMap.size() )
+ if ( o3tl::make_unsigned(nIndex) >= maMap.size() )
throw lang::IndexOutOfBoundsException();
return OUString();
@@ -521,7 +522,7 @@ OUString SAL_CALL SwXStringKeyMap::getKeyByIndex(::sal_Int32 nIndex)
uno::Any SAL_CALL SwXStringKeyMap::getValueByIndex(::sal_Int32 nIndex)
{
- if ( static_cast<sal_uInt32>(nIndex) >= maMap.size() )
+ if ( o3tl::make_unsigned(nIndex) >= maMap.size() )
throw lang::IndexOutOfBoundsException();
return uno::Any();
diff --git a/sw/source/filter/basflt/fltshell.cxx b/sw/source/filter/basflt/fltshell.cxx
index deffb3c791f4..e6ab4c67fe47 100644
--- a/sw/source/filter/basflt/fltshell.cxx
+++ b/sw/source/filter/basflt/fltshell.cxx
@@ -20,6 +20,7 @@
#include <memory>
#include <sal/config.h>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <cstddef>
@@ -355,7 +356,7 @@ SwFltStackEntry* SwFltControlStack::SetAttr(const SwPosition& rPos,
OSL_ENSURE(!nAttrId ||
(POOLATTR_BEGIN <= nAttrId && POOLATTR_END > nAttrId) ||
- (RES_FLTRATTR_BEGIN <= nAttrId && sal_uInt16(RES_FLTRATTR_END) > nAttrId),
+ (RES_FLTRATTR_BEGIN <= nAttrId && o3tl::make_unsigned(RES_FLTRATTR_END) > nAttrId),
"Wrong id for attribute");
auto aI = m_Entries.begin();
diff --git a/sw/source/filter/html/htmlplug.cxx b/sw/source/filter/html/htmlplug.cxx
index bf35d49b244d..ddff54de50ab 100644
--- a/sw/source/filter/html/htmlplug.cxx
+++ b/sw/source/filter/html/htmlplug.cxx
@@ -76,6 +76,7 @@
#include <comphelper/propertysequence.hxx>
#include <filter/msfilter/msoleexp.hxx>
#include <comphelper/fileurl.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <comphelper/propertyvalue.hxx>
@@ -1490,7 +1491,7 @@ Writer& OutHTML_FrameFormatOLENodeGrf( Writer& rWrt, const SwFrameFormat& rFrame
aMediaDescriptor["FilterOptions"] <<= OUString("SkipHeaderFooter");
aMediaDescriptor["OutputStream"] <<= xOutputStream;
xStorable->storeToURL("private:stream", aMediaDescriptor.getAsConstPropertyValueList());
- SAL_WARN_IF(aStream.GetSize()>=static_cast<sal_uInt64>(SAL_MAX_INT32), "sw.html", "Stream can't fit in OString");
+ SAL_WARN_IF(aStream.GetSize()>=o3tl::make_unsigned(SAL_MAX_INT32), "sw.html", "Stream can't fit in OString");
OString aData(static_cast<const char*>(aStream.GetData()), static_cast<sal_Int32>(aStream.GetSize()));
// Wrap output in a <span> tag to avoid 'HTML parser error: Unexpected end tag: p'
HTMLOutFuncs::Out_AsciiTag(rWrt.Strm(), rHTMLWrt.GetNamespace() + OOO_STRING_SVTOOLS_HTML_span);
diff --git a/sw/source/filter/ww8/wrtww8.cxx b/sw/source/filter/ww8/wrtww8.cxx
index 5815d7cb72b8..84bf1a645531 100644
--- a/sw/source/filter/ww8/wrtww8.cxx
+++ b/sw/source/filter/ww8/wrtww8.cxx
@@ -27,6 +27,7 @@
#include <map>
#include <hintids.hxx>
#include <string.h>
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <sal/log.hxx>
#include <docsh.hxx>
@@ -1205,7 +1206,7 @@ bool WW8_WrFkp::Append( WW8_FC nEndFc, sal_uInt16 nVarLen, const sal_uInt8* pSpr
nPos &= 0xFFFE; // Pos for Sprms ( gerade Pos )
}
- if( static_cast<sal_uInt16>(nPos) <= ( nIMax + 2U ) * 4U + ( nIMax + 1U ) * nItemSize )
+ if( o3tl::make_unsigned(nPos) <= ( nIMax + 2U ) * 4U + ( nIMax + 1U ) * nItemSize )
// does it fits after the CPs and offsets?
return false; // no
@@ -1418,7 +1419,7 @@ void WW8_WrPct::SetParaBreak()
WW8_CP WW8_WrPct::Fc2Cp( sal_uLong nFc ) const
{
- OSL_ENSURE( nFc >= static_cast<sal_uLong>(nOldFc), "FilePos lies in front of last piece" );
+ OSL_ENSURE( nFc >= o3tl::make_unsigned(nOldFc), "FilePos lies in front of last piece" );
OSL_ENSURE( ! m_Pcts.empty(), "Fc2Cp no piece available" );
nFc -= nOldFc;
diff --git a/sw/source/filter/ww8/ww8atr.cxx b/sw/source/filter/ww8/ww8atr.cxx
index 6d3749b75d47..945badc3bfb1 100644
--- a/sw/source/filter/ww8/ww8atr.cxx
+++ b/sw/source/filter/ww8/ww8atr.cxx
@@ -24,6 +24,7 @@
#include <hintids.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
#include <sal/log.hxx>
@@ -3750,7 +3751,7 @@ sal_uLong WW8Export::ReplaceCr( sal_uInt8 nChar )
SvStream& rStrm = Strm();
sal_uLong nRetPos = 0, nPos = rStrm.Tell();
//If there is at least two characters already output
- if (nPos - 2 >= sal_uLong(pFib->m_fcMin))
+ if (nPos - 2 >= o3tl::make_unsigned(pFib->m_fcMin))
{
sal_uInt16 nUCode=0;
@@ -3760,7 +3761,7 @@ sal_uLong WW8Export::ReplaceCr( sal_uInt8 nChar )
if (nUCode == 0x0d) // CR ?
{
if ((nChar == 0x0c) &&
- (nPos - 4 >= sal_uLong(pFib->m_fcMin)))
+ (nPos - 4 >= o3tl::make_unsigned(pFib->m_fcMin)))
{
rStrm.SeekRel(-4);
rStrm.ReadUInt16( nUCode );
diff --git a/sw/source/filter/ww8/ww8par.cxx b/sw/source/filter/ww8/ww8par.cxx
index 92aa8e00c2e8..eaa7e9d957ae 100644
--- a/sw/source/filter/ww8/ww8par.cxx
+++ b/sw/source/filter/ww8/ww8par.cxx
@@ -127,6 +127,7 @@
#include <basic/basmgr.hxx>
#include "ww8toolbar.hxx"
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <breakit.hxx>
@@ -2841,7 +2842,7 @@ rtl_TextEncoding SwWW8ImplReader::GetCurrentCharSet()
eSrcCharSet = GetCharSetFromLanguage();
else if (!m_aFontSrcCharSets.empty())
eSrcCharSet = m_aFontSrcCharSets.top();
- if ((eSrcCharSet == RTL_TEXTENCODING_DONTKNOW) && m_nCharFormat >= 0 && static_cast<size_t>(m_nCharFormat) < m_vColl.size() )
+ if ((eSrcCharSet == RTL_TEXTENCODING_DONTKNOW) && m_nCharFormat >= 0 && o3tl::make_unsigned(m_nCharFormat) < m_vColl.size() )
eSrcCharSet = m_vColl[m_nCharFormat].GetCharSet();
if ((eSrcCharSet == RTL_TEXTENCODING_DONTKNOW) && StyleExists(m_nCurrentColl) && m_nCurrentColl < m_vColl.size())
eSrcCharSet = m_vColl[m_nCurrentColl].GetCharSet();
@@ -2865,7 +2866,7 @@ rtl_TextEncoding SwWW8ImplReader::GetCurrentCJKCharSet()
{
if (!m_aFontSrcCJKCharSets.empty())
eSrcCharSet = m_aFontSrcCJKCharSets.top();
- if ((eSrcCharSet == RTL_TEXTENCODING_DONTKNOW) && m_nCharFormat >= 0 && static_cast<size_t>(m_nCharFormat) < m_vColl.size() )
+ if ((eSrcCharSet == RTL_TEXTENCODING_DONTKNOW) && m_nCharFormat >= 0 && o3tl::make_unsigned(m_nCharFormat) < m_vColl.size() )
eSrcCharSet = m_vColl[m_nCharFormat].GetCJKCharSet();
if (eSrcCharSet == RTL_TEXTENCODING_DONTKNOW && StyleExists(m_nCurrentColl) && m_nCurrentColl < m_vColl.size())
eSrcCharSet = m_vColl[m_nCurrentColl].GetCJKCharSet();
@@ -3491,7 +3492,7 @@ bool SwWW8ImplReader::ReadChars(WW8_CP& rPos, WW8_CP nNextAttr, long nTextEnd,
if (m_bSymbol) // Insert special chars
{
sal_uInt64 nMaxPossible = m_pStrm->remainingSize();
- if (static_cast<sal_uInt64>(nRequested) > nMaxPossible)
+ if (o3tl::make_unsigned(nRequested) > nMaxPossible)
{
SAL_WARN("sw.ww8", "document claims to have more characters, " << nRequested << " than remaining, " << nMaxPossible);
nRequested = nMaxPossible;
@@ -6548,7 +6549,7 @@ bool SwWW8ImplReader::InEqualApo(int nLvl) const
// If we are in a table, see if an apo was inserted at the level below the table.
if (nLvl)
--nLvl;
- if (nLvl < 0 || static_cast<size_t>(nLvl) >= m_aApos.size())
+ if (nLvl < 0 || o3tl::make_unsigned(nLvl) >= m_aApos.size())
return false;
return m_aApos[nLvl];
}
diff --git a/sw/source/filter/ww8/ww8par2.cxx b/sw/source/filter/ww8/ww8par2.cxx
index 53069581d400..8a52b7eb9641 100644
--- a/sw/source/filter/ww8/ww8par2.cxx
+++ b/sw/source/filter/ww8/ww8par2.cxx
@@ -21,6 +21,7 @@
#include <sal/log.hxx>
#include <comphelper/string.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/solar.h>
#include <vcl/font.hxx>
#include <hintids.hxx>
@@ -786,7 +787,7 @@ void SwWW8ImplReader::Read_ANLevelDesc( sal_uInt16, const sal_uInt8* pData, shor
return;
}
- if (static_cast<size_t>(nLen) < sizeof(WW8_ANLD))
+ if (o3tl::make_unsigned(nLen) < sizeof(WW8_ANLD))
{
SAL_WARN("sw.ww8", "ANLevelDesc property is " << nLen << " long, needs to be at least " << sizeof(WW8_ANLD));
m_nSwNumLevel = 0xff;
@@ -854,7 +855,7 @@ void SwWW8ImplReader::Read_OLST( sal_uInt16, const sal_uInt8* pData, short nLen
if (nLen <= 0)
return;
- if (static_cast<size_t>(nLen) < sizeof(WW8_OLST))
+ if (o3tl::make_unsigned(nLen) < sizeof(WW8_OLST))
{
SAL_WARN("sw.ww8", "WW8_OLST property is " << nLen << " long, needs to be at least " << sizeof(WW8_OLST));
return;
@@ -2858,9 +2859,9 @@ WW8SelBoxInfo* WW8TabDesc::FindMergeGroup(short nX1, short nWidth, bool bExact)
bool WW8TabDesc::IsValidCell(short nCol) const
{
- return (static_cast<size_t>(nCol) < SAL_N_ELEMENTS(m_pActBand->bExist)) &&
+ return (o3tl::make_unsigned(nCol) < SAL_N_ELEMENTS(m_pActBand->bExist)) &&
m_pActBand->bExist[nCol] &&
- static_cast<sal_uInt16>(m_nCurrentRow) < m_pTabLines->size();
+ o3tl::make_unsigned(m_nCurrentRow) < m_pTabLines->size();
}
bool WW8TabDesc::InFirstParaInCell() const
@@ -2886,7 +2887,7 @@ void WW8TabDesc::SetPamInCell(short nWwCol, bool bPam)
sal_uInt16 nCol = m_pActBand->transCell(nWwCol);
- if (static_cast<sal_uInt16>(m_nCurrentRow) >= m_pTabLines->size())
+ if (o3tl::make_unsigned(m_nCurrentRow) >= m_pTabLines->size())
{
OSL_ENSURE(false, "Actual row bigger than expected." );
if (bPam)
diff --git a/sw/source/filter/ww8/ww8par6.cxx b/sw/source/filter/ww8/ww8par6.cxx
index bb435b9a6485..9b1c95217cb8 100644
--- a/sw/source/filter/ww8/ww8par6.cxx
+++ b/sw/source/filter/ww8/ww8par6.cxx
@@ -18,6 +18,7 @@
*/
#include <stdlib.h>
+#include <o3tl/safeint.hxx>
#include <svl/itemiter.hxx>
#include <svl/grabbagitem.hxx>
#include <rtl/tencinfo.h>
@@ -598,7 +599,7 @@ void wwSectionManager::GetPageULData(const wwSection &rSection,
// #i19922# - correction:
// consider that <nWWUp> can be negative, compare only if it's positive
if ( nWWUp > 0 &&
- static_cast<sal_uInt32>(abs(nWWUp)) >= nWWHTop )
+ o3tl::make_unsigned(abs(nWWUp)) >= nWWHTop )
rData.nSwHLo = nWWUp - nWWHTop;
else
rData.nSwHLo = 0;
@@ -616,7 +617,7 @@ void wwSectionManager::GetPageULData(const wwSection &rSection,
rData.nSwLo = nWWFBot; // footer -> convert
// #i19922# - correction: consider that <nWWLo> can be negative, compare only if it's positive
if ( nWWLo > 0 &&
- static_cast<sal_uInt32>(abs(nWWLo)) >= nWWFBot )
+ o3tl::make_unsigned(abs(nWWLo)) >= nWWFBot )
rData.nSwFUp = nWWLo - nWWFBot;
else
rData.nSwFUp = 0;
diff --git a/sw/source/filter/ww8/ww8scan.cxx b/sw/source/filter/ww8/ww8scan.cxx
index e3c5ac3a4098..89cba1fce16f 100644
--- a/sw/source/filter/ww8/ww8scan.cxx
+++ b/sw/source/filter/ww8/ww8scan.cxx
@@ -7108,7 +7108,7 @@ namespace
{
assert(p <= pEnd);
assert(value != nullptr);
- if (offset >= static_cast<std::size_t>(pEnd - p)) {
+ if (offset >= o3tl::make_unsigned(pEnd - p)) {
return false;
}
*value = p[offset];
@@ -7121,7 +7121,7 @@ namespace
{
assert(p <= pEnd);
assert(value != nullptr);
- if (offset > static_cast<std::size_t>(pEnd - p)
+ if (offset > o3tl::make_unsigned(pEnd - p)
|| static_cast<std::size_t>(pEnd - p) - offset < 2)
{
return false;
@@ -7135,7 +7135,7 @@ namespace
{
assert(p <= pEnd);
assert(pEnd - p <= SAL_MAX_INT32);
- if (offset >= static_cast<std::size_t>(pEnd - p)) {
+ if (offset >= o3tl::make_unsigned(pEnd - p)) {
return -1;
}
void const * p2 = std::memchr(
@@ -7163,7 +7163,7 @@ WW8Fonts::WW8Fonts( SvStream& rSt, WW8Fib const & rFib )
sal_Int32 nFFn = rFib.m_lcbSttbfffn - 2;
const sal_uInt64 nMaxPossible = rSt.remainingSize();
- if (static_cast<sal_uInt64>(nFFn) > nMaxPossible)
+ if (o3tl::make_unsigned(nFFn) > nMaxPossible)
{
SAL_WARN("sw.ww8", "FFN structure longer than available data");
nFFn = nMaxPossible;
diff --git a/sw/source/filter/ww8/ww8toolbar.cxx b/sw/source/filter/ww8/ww8toolbar.cxx
index e4909b83da01..3cb4f4e335f9 100644
--- a/sw/source/filter/ww8/ww8toolbar.cxx
+++ b/sw/source/filter/ww8/ww8toolbar.cxx
@@ -19,6 +19,7 @@
#include <comphelper/documentinfo.hxx>
#include <comphelper/processfactory.hxx>
#include <comphelper/sequence.hxx>
+#include <o3tl/safeint.hxx>
#include <sfx2/objsh.hxx>
#include <tools/diagnose_ex.h>
#include <unotools/configmgr.hxx>
@@ -165,7 +166,7 @@ bool SwCTBWrapper::Read( SvStream& rS )
}
for ( const auto& rIndex : dropDownMenuIndices )
{
- if (rIndex < 0 || static_cast<size_t>(rIndex) >= rCustomizations.size())
+ if (rIndex < 0 || o3tl::make_unsigned(rIndex) >= rCustomizations.size())
continue;
rCustomizations[rIndex].bIsDroppedMenuTB = true;
}
@@ -760,7 +761,7 @@ bool PlfMcd::Read(SvStream &rS)
if (iMac < 0)
return false;
auto nMaxPossibleRecords = rS.remainingSize() / 24 /*sizeof MCD*/;
- if (static_cast<sal_uInt32>(iMac) > nMaxPossibleRecords)
+ if (o3tl::make_unsigned(iMac) > nMaxPossibleRecords)
{
SAL_WARN("sw.ww8", iMac << " records claimed, but max possible is " << nMaxPossibleRecords);
iMac = nMaxPossibleRecords;
@@ -795,7 +796,7 @@ bool PlfAcd::Read( SvStream &rS)
if (iMac < 0)
return false;
auto nMaxPossibleRecords = rS.remainingSize() / (sizeof(sal_uInt16)*2);
- if (static_cast<sal_uInt32>(iMac) > nMaxPossibleRecords)
+ if (o3tl::make_unsigned(iMac) > nMaxPossibleRecords)
{
SAL_WARN("sw.ww8", iMac << " records claimed, but max possible is " << nMaxPossibleRecords);
iMac = nMaxPossibleRecords;
@@ -831,7 +832,7 @@ bool PlfKme::Read(SvStream &rS)
{
//each Kme is 14 bytes in size
size_t nMaxAvailableRecords = rS.remainingSize() / 14;
- if (static_cast<sal_uInt32>(iMac) > nMaxAvailableRecords)
+ if (o3tl::make_unsigned(iMac) > nMaxAvailableRecords)
return false;
rgkme.reset( new Kme[ iMac ] );
diff --git a/sw/source/ui/dbui/mmaddressblockpage.cxx b/sw/source/ui/dbui/mmaddressblockpage.cxx
index a8545852032e..11d884ec6652 100644
--- a/sw/source/ui/dbui/mmaddressblockpage.cxx
+++ b/sw/source/ui/dbui/mmaddressblockpage.cxx
@@ -22,6 +22,7 @@
#include <swtypes.hxx>
#include "addresslistdialog.hxx"
#include <editeng/eeitem.hxx>
+#include <o3tl/safeint.hxx>
#include <svl/grabbagitem.hxx>
#include <svl/itemset.hxx>
#include <vcl/event.hxx>
@@ -864,7 +865,7 @@ void SwAssignFieldsControl::Init(SwAssignFieldsDialog* pDialog, SwMailMergeConfi
rNewLB.append_text(rField);
//select the ListBox
//if there is an assignment
- if(static_cast<sal_uInt32>(aAssignments.getLength()) > i && !aAssignments[i].isEmpty())
+ if(o3tl::make_unsigned(aAssignments.getLength()) > i && !aAssignments[i].isEmpty())
rNewLB.set_active_text(aAssignments[i]);
else //otherwise the current column name may match one of the db columns
rNewLB.set_active_text(rHeader);
diff --git a/sw/source/ui/fldui/fldref.cxx b/sw/source/ui/fldui/fldref.cxx
index a64f2eb20831..9a94726ad74d 100644
--- a/sw/source/ui/fldui/fldref.cxx
+++ b/sw/source/ui/fldui/fldref.cxx
@@ -33,6 +33,7 @@
#include <unotools/charclass.hxx>
#include <comphelper/string.hxx>
+#include <o3tl/safeint.hxx>
#define REFFLDFLAG 0x4000
#define REFFLDFLAG_BOOKMARK 0x4800
@@ -191,7 +192,7 @@ void SwFieldRefPage::Reset(const SfxItemSet* )
const size_t nFieldTypeCnt = pSh->GetFieldTypeCount(SwFieldIds::SetExp);
- OSL_ENSURE( nFieldTypeCnt < static_cast<size_t>(REFFLDFLAG), "<SwFieldRefPage::Reset> - Item index will overlap flags!" );
+ OSL_ENSURE( nFieldTypeCnt < o3tl::make_unsigned(REFFLDFLAG), "<SwFieldRefPage::Reset> - Item index will overlap flags!" );
for (size_t n = 0; n < nFieldTypeCnt; ++n)
{
diff --git a/sw/source/ui/frmdlg/frmpage.cxx b/sw/source/ui/frmdlg/frmpage.cxx
index 5ba7541fb468..00188e194f9a 100644
--- a/sw/source/ui/frmdlg/frmpage.cxx
+++ b/sw/source/ui/frmdlg/frmpage.cxx
@@ -24,6 +24,7 @@
#include <cmdid.h>
#include <hintids.hxx>
#include <bitmaps.hlst>
+#include <o3tl/safeint.hxx>
#include <vcl/mnemonic.hxx>
#include <svl/stritem.hxx>
#include <sfx2/htmlmode.hxx>
@@ -1595,7 +1596,7 @@ sal_Int16 SwFramePage::GetAlignment(FrameMap const *pMap, sal_Int32 nMapPos,
const size_t nMapCount = ::lcl_GetFrameMapCount(pMap);
- if (static_cast<size_t>(nMapPos) >= nMapCount)
+ if (o3tl::make_unsigned(nMapPos) >= nMapCount)
return 0;
// i#22341 special handling also for map <aVCharMap>,
diff --git a/sw/source/ui/index/cnttab.cxx b/sw/source/ui/index/cnttab.cxx
index 0c181975d5bf..d5aa63eeeae6 100644
--- a/sw/source/ui/index/cnttab.cxx
+++ b/sw/source/ui/index/cnttab.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <sal/log.hxx>
#include <svl/style.hxx>
#include <vcl/weld.hxx>
@@ -3678,7 +3681,7 @@ bool SwEntryBrowseBox::SeekRow( long nRow )
OUString SwEntryBrowseBox::GetCellText(long nRow, sal_uInt16 nColumn) const
{
OUString pRet;
- if (static_cast<size_t>(nRow) < m_Entries.size())
+ if (o3tl::make_unsigned(nRow) < m_Entries.size())
{
const AutoMarkEntry* pEntry = m_Entries[ nRow ].get();
switch(nColumn)
diff --git a/sw/source/uibase/dbui/mailmergehelper.cxx b/sw/source/uibase/dbui/mailmergehelper.cxx
index ea3573dd8f5c..0981bce7fdaa 100644
--- a/sw/source/uibase/dbui/mailmergehelper.cxx
+++ b/sw/source/uibase/dbui/mailmergehelper.cxx
@@ -32,6 +32,7 @@
#include <com/sun/star/mail/MailServiceProvider.hpp>
#include <com/sun/star/mail/XSmtpService.hpp>
#include <comphelper/processfactory.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/event.hxx>
#include <vcl/settings.hxx>
#include <vcl/svapp.hxx>
@@ -460,7 +461,7 @@ bool SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
bHandled = true;
break;
case KEY_DOWN:
- if(pImpl->aAddresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
+ if(pImpl->aAddresses.size() > o3tl::make_unsigned(pImpl->nSelectedAddress + pImpl->nColumns))
++nSelectedRow;
bHandled = true;
break;
@@ -470,7 +471,7 @@ bool SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
bHandled = true;
break;
case KEY_RIGHT:
- if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
+ if(nSelectedColumn < o3tl::make_unsigned(pImpl->nColumns - 1) &&
pImpl->aAddresses.size() - 1 > pImpl->nSelectedAddress )
++nSelectedColumn;
bHandled = true;
diff --git a/sw/source/uibase/uno/unoatxt.cxx b/sw/source/uibase/uno/unoatxt.cxx
index 3d7901bcfcef..0b2d341b309b 100644
--- a/sw/source/uibase/uno/unoatxt.cxx
+++ b/sw/source/uibase/uno/unoatxt.cxx
@@ -23,6 +23,7 @@
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
#include <com/sun/star/lang/WrappedTargetRuntimeException.hpp>
#include <com/sun/star/container/ElementExistException.hpp>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <rtl/character.hxx>
#include <vcl/svapp.hxx>
@@ -69,7 +70,7 @@ SwXAutoTextContainer::~SwXAutoTextContainer()
sal_Int32 SwXAutoTextContainer::getCount()
{
- OSL_ENSURE(pGlossaries->GetGroupCnt() < static_cast<size_t>(SAL_MAX_INT32),
+ OSL_ENSURE(pGlossaries->GetGroupCnt() < o3tl::make_unsigned(SAL_MAX_INT32),
"SwXAutoTextContainer::getCount: too many items");
return static_cast<sal_Int32>(pGlossaries->GetGroupCnt());
}
@@ -78,7 +79,7 @@ uno::Any SwXAutoTextContainer::getByIndex(sal_Int32 nIndex)
{
SolarMutexGuard aGuard;
const size_t nCount = pGlossaries->GetGroupCnt();
- if ( nIndex < 0 || static_cast<size_t>(nIndex) >= nCount )
+ if ( nIndex < 0 || o3tl::make_unsigned(nIndex) >= nCount )
throw lang::IndexOutOfBoundsException();
return getByName(pGlossaries->GetGroupName( static_cast<size_t>(nIndex) ));
}
@@ -114,7 +115,7 @@ uno::Sequence< OUString > SwXAutoTextContainer::getElementNames()
{
SolarMutexGuard aGuard;
const size_t nCount = pGlossaries->GetGroupCnt();
- OSL_ENSURE(nCount < static_cast<size_t>(SAL_MAX_INT32),
+ OSL_ENSURE(nCount < o3tl::make_unsigned(SAL_MAX_INT32),
"SwXAutoTextContainer::getElementNames: too many groups");
uno::Sequence< OUString > aGroupNames(static_cast<sal_Int32>(nCount));
diff --git a/test/source/sheet/xdatapilotdescriptor.cxx b/test/source/sheet/xdatapilotdescriptor.cxx
index aa333a073c72..a9cbcf5b125c 100644
--- a/test/source/sheet/xdatapilotdescriptor.cxx
+++ b/test/source/sheet/xdatapilotdescriptor.cxx
@@ -16,6 +16,7 @@
#include <cppunit/TestAssert.h>
+#include <o3tl/safeint.hxx>
#include <rtl/ustring.hxx>
using namespace css;
@@ -177,7 +178,7 @@ void XDataPilotDescriptor::testGetHiddenFields()
void XDataPilotDescriptor::checkName( uno::Reference< container::XIndexAccess > const & xIndex, sal_Int32 nIndex )
{
CPPUNIT_ASSERT(xIndex.is());
- CPPUNIT_ASSERT(maFieldNames.size() >= static_cast<size_t>(nIndex));
+ CPPUNIT_ASSERT(maFieldNames.size() >= o3tl::make_unsigned(nIndex));
for (sal_Int32 i = 0; i < xIndex->getCount(); ++i)
{
diff --git a/toolkit/source/awt/animatedimagespeer.cxx b/toolkit/source/awt/animatedimagespeer.cxx
index e056ef04d55c..e833f366aa21 100644
--- a/toolkit/source/awt/animatedimagespeer.cxx
+++ b/toolkit/source/awt/animatedimagespeer.cxx
@@ -31,6 +31,7 @@
#include <comphelper/namedvaluecollection.hxx>
#include <comphelper/processfactory.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ustrbuf.hxx>
#include <tools/diagnose_ex.h>
#include <tools/urlobj.hxx>
@@ -245,7 +246,7 @@ namespace toolkit
// found a set?
std::vector< Image > aImages;
- if ( ( nPreferredSet >= 0 ) && ( size_t( nPreferredSet ) < nImageSetCount ) )
+ if ( ( nPreferredSet >= 0 ) && ( o3tl::make_unsigned( nPreferredSet ) < nImageSetCount ) )
{
// => set the images
::std::vector< CachedImage > const& rImageSet( i_data.aCachedImageSets[ nPreferredSet ] );
diff --git a/toolkit/source/controls/animatedimages.cxx b/toolkit/source/controls/animatedimages.cxx
index efa48cec0b1f..d35224d3ac93 100644
--- a/toolkit/source/controls/animatedimages.cxx
+++ b/toolkit/source/controls/animatedimages.cxx
@@ -31,7 +31,7 @@
#include <com/sun/star/container/XContainerListener.hpp>
#include <com/sun/star/uno/XComponentContext.hpp>
#include <com/sun/star/util/XModifyListener.hpp>
-
+#include <o3tl/safeint.hxx>
#include <toolkit/controls/unocontrolbase.hxx>
#include <toolkit/controls/unocontrolmodel.hxx>
@@ -213,7 +213,7 @@ namespace toolkit {
void lcl_checkIndex( const AnimatedImagesControlModel_Data& i_data, const sal_Int32 i_index, const Reference< XInterface >& i_context,
const bool i_forInsert = false )
{
- if ( ( i_index < 0 ) || ( size_t( i_index ) > i_data.aImageSets.size() + ( i_forInsert ? 1 : 0 ) ) )
+ if ( ( i_index < 0 ) || ( o3tl::make_unsigned( i_index ) > i_data.aImageSets.size() + ( i_forInsert ? 1 : 0 ) ) )
throw IndexOutOfBoundsException( OUString(), i_context );
}
diff --git a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx
index 9d6a28fa6625..8b97158d0df0 100644
--- a/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx
+++ b/toolkit/source/controls/grid/defaultgridcolumnmodel.cxx
@@ -33,6 +33,7 @@
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/ref.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
@@ -177,7 +178,7 @@ private:
{
::comphelper::ComponentGuard aGuard( *this, rBHelper );
- if ( ( i_columnIndex < 0 ) || ( size_t( i_columnIndex ) >= m_aColumns.size() ) )
+ if ( ( i_columnIndex < 0 ) || ( o3tl::make_unsigned( i_columnIndex ) >= m_aColumns.size() ) )
throw css::lang::IndexOutOfBoundsException( OUString(), *this );
Columns::iterator const pos = m_aColumns.begin() + i_columnIndex;
diff --git a/toolkit/source/controls/grid/defaultgriddatamodel.cxx b/toolkit/source/controls/grid/defaultgriddatamodel.cxx
index e29315ddd79c..1945204c559b 100644
--- a/toolkit/source/controls/grid/defaultgriddatamodel.cxx
+++ b/toolkit/source/controls/grid/defaultgriddatamodel.cxx
@@ -27,6 +27,7 @@
#include <cppuhelper/basemutex.hxx>
#include <cppuhelper/compbase.hxx>
#include <cppuhelper/supportsservice.hxx>
+#include <o3tl/safeint.hxx>
#include <algorithm>
#include <vector>
@@ -153,13 +154,13 @@ private:
DefaultGridDataModel::CellData const & DefaultGridDataModel::impl_getCellData_throw( sal_Int32 const i_column, sal_Int32 const i_row ) const
{
- if ( ( i_row < 0 ) || ( size_t( i_row ) > m_aData.size() )
+ if ( ( i_row < 0 ) || ( o3tl::make_unsigned( i_row ) > m_aData.size() )
|| ( i_column < 0 ) || ( i_column > m_nColumnCount )
)
throw IndexOutOfBoundsException( OUString(), *const_cast< DefaultGridDataModel* >( this ) );
RowData const & rRow( m_aData[ i_row ] );
- if ( size_t( i_column ) < rRow.size() )
+ if ( o3tl::make_unsigned( i_column ) < rRow.size() )
return rRow[ i_column ];
static CellData s_aEmpty;
@@ -169,8 +170,8 @@ private:
DefaultGridDataModel::RowData& DefaultGridDataModel::impl_getRowDataAccess_throw( sal_Int32 const i_rowIndex, size_t const i_requiredColumnCount )
{
- OSL_ENSURE( i_requiredColumnCount <= size_t( m_nColumnCount ), "DefaultGridDataModel::impl_getRowDataAccess_throw: invalid column count!" );
- if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
+ OSL_ENSURE( i_requiredColumnCount <= o3tl::make_unsigned( m_nColumnCount ), "DefaultGridDataModel::impl_getRowDataAccess_throw: invalid column count!" );
+ if ( ( i_rowIndex < 0 ) || ( o3tl::make_unsigned( i_rowIndex ) >= m_aData.size() ) )
throw IndexOutOfBoundsException( OUString(), *this );
RowData& rRowData( m_aData[ i_rowIndex ] );
@@ -208,7 +209,7 @@ private:
{
::comphelper::ComponentGuard aGuard( *this, rBHelper );
- if ( ( i_row < 0 ) || ( size_t( i_row ) >= m_aRowHeaders.size() ) )
+ if ( ( i_row < 0 ) || ( o3tl::make_unsigned( i_row ) >= m_aRowHeaders.size() ) )
throw IndexOutOfBoundsException( OUString(), *this );
return m_aRowHeaders[ i_row ];
@@ -328,7 +329,7 @@ private:
{
::comphelper::ComponentGuard aGuard( *this, rBHelper );
- if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
+ if ( ( i_rowIndex < 0 ) || ( o3tl::make_unsigned( i_rowIndex ) >= m_aData.size() ) )
throw IndexOutOfBoundsException( OUString(), *this );
m_aRowHeaders.erase( m_aRowHeaders.begin() + i_rowIndex );
@@ -375,7 +376,7 @@ private:
{
::comphelper::ComponentGuard aGuard( *this, rBHelper );
- if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aData.size() ) )
+ if ( ( i_rowIndex < 0 ) || ( o3tl::make_unsigned( i_rowIndex ) >= m_aData.size() ) )
throw IndexOutOfBoundsException( OUString(), *this );
if ( i_columnIndexes.getLength() != i_values.getLength() )
@@ -395,7 +396,7 @@ private:
for ( sal_Int32 col = 0; col < columnCount; ++col )
{
sal_Int32 const columnIndex = i_columnIndexes[ col ];
- if ( size_t( columnIndex ) >= rDataRow.size() )
+ if ( o3tl::make_unsigned( columnIndex ) >= rDataRow.size() )
rDataRow.resize( columnIndex + 1 );
rDataRow[ columnIndex ].first = i_values[ col ];
@@ -416,7 +417,7 @@ private:
{
::comphelper::ComponentGuard aGuard( *this, rBHelper );
- if ( ( i_rowIndex < 0 ) || ( size_t( i_rowIndex ) >= m_aRowHeaders.size() ) )
+ if ( ( i_rowIndex < 0 ) || ( o3tl::make_unsigned( i_rowIndex ) >= m_aRowHeaders.size() ) )
throw IndexOutOfBoundsException( OUString(), *this );
m_aRowHeaders[ i_rowIndex ] = i_heading;
diff --git a/toolkit/source/controls/grid/sortablegriddatamodel.cxx b/toolkit/source/controls/grid/sortablegriddatamodel.cxx
index 711c7c23fa8d..ffbb6528dc62 100644
--- a/toolkit/source/controls/grid/sortablegriddatamodel.cxx
+++ b/toolkit/source/controls/grid/sortablegriddatamodel.cxx
@@ -38,6 +38,7 @@
#include <cppuhelper/supportsservice.hxx>
#include <tools/diagnose_ex.h>
#include <i18nlangtag/languagetag.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <vcl/settings.hxx>
@@ -437,7 +438,7 @@ void lcl_clear( STLCONTAINER& i_container )
OSL_ENSURE( false, "SortableGridDataModel::rowsRemoved: missing implementation - removal of multiple rows!" );
needReIndex = true;
}
- else if ( size_t( i_event.FirstRow ) >= m_privateToPublicRowIndex.size() )
+ else if ( o3tl::make_unsigned( i_event.FirstRow ) >= m_privateToPublicRowIndex.size() )
{
OSL_ENSURE( false, "SortableGridDataModel::rowsRemoved: inconsistent/wrong data!" );
needReIndex = true;
@@ -891,7 +892,7 @@ void lcl_clear( STLCONTAINER& i_container )
// no need to translate anything
return i_publicRowIndex;
- ENSURE_OR_RETURN( size_t( i_publicRowIndex ) < m_publicToPrivateRowIndex.size(),
+ ENSURE_OR_RETURN( o3tl::make_unsigned( i_publicRowIndex ) < m_publicToPrivateRowIndex.size(),
"SortableGridDataModel::impl_getPrivateRowIndex_throw: inconsistency!", i_publicRowIndex );
// obviously the translation table contains too few elements - it should have exactly |getRowCount()|
// elements
@@ -909,7 +910,7 @@ void lcl_clear( STLCONTAINER& i_container )
if ( i_privateRowIndex < 0 )
return i_privateRowIndex;
- ENSURE_OR_RETURN( size_t( i_privateRowIndex ) < m_privateToPublicRowIndex.size(),
+ ENSURE_OR_RETURN( o3tl::make_unsigned( i_privateRowIndex ) < m_privateToPublicRowIndex.size(),
"SortableGridDataModel::impl_getPublicRowIndex_nothrow: invalid index!", i_privateRowIndex );
return m_privateToPublicRowIndex[ i_privateRowIndex ];
diff --git a/toolkit/source/controls/unocontrols.cxx b/toolkit/source/controls/unocontrols.cxx
index 81eab576bd30..b80d89f2d01b 100644
--- a/toolkit/source/controls/unocontrols.cxx
+++ b/toolkit/source/controls/unocontrols.cxx
@@ -28,7 +28,7 @@
#include <com/sun/star/util/Date.hpp>
#include <com/sun/star/awt/ImageScaleMode.hpp>
-
+#include <o3tl/safeint.hxx>
#include <toolkit/controls/formattedcontrol.hxx>
#include <toolkit/controls/unocontrols.hxx>
#include <toolkit/helper/property.hxx>
@@ -2417,8 +2417,8 @@ void UnoControlListBoxModel::impl_handleInsert( const sal_Int32 i_nItemPosition,
// sync with legacy StringItemList property
::std::vector< OUString > aStringItems;
impl_getStringItemList( aStringItems );
- OSL_ENSURE( size_t( i_nItemPosition ) <= aStringItems.size(), "UnoControlListBoxModel::impl_handleInsert" );
- if ( size_t( i_nItemPosition ) <= aStringItems.size() )
+ OSL_ENSURE( o3tl::make_unsigned( i_nItemPosition ) <= aStringItems.size(), "UnoControlListBoxModel::impl_handleInsert" );
+ if ( o3tl::make_unsigned( i_nItemPosition ) <= aStringItems.size() )
{
const OUString sItemText( !!i_rItemText ? *i_rItemText : OUString() );
aStringItems.insert( aStringItems.begin() + i_nItemPosition, sItemText );
@@ -2442,8 +2442,8 @@ void UnoControlListBoxModel::impl_handleRemove( const sal_Int32 i_nItemPosition,
impl_getStringItemList( aStringItems );
if ( !bAllItems )
{
- OSL_ENSURE( size_t( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleRemove" );
- if ( size_t( i_nItemPosition ) < aStringItems.size() )
+ OSL_ENSURE( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleRemove" );
+ if ( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size() )
{
aStringItems.erase( aStringItems.begin() + i_nItemPosition );
}
@@ -2480,8 +2480,8 @@ void UnoControlListBoxModel::impl_handleModify( const sal_Int32 i_nItemPosition,
// sync with legacy StringItemList property
::std::vector< OUString > aStringItems;
impl_getStringItemList( aStringItems );
- OSL_ENSURE( size_t( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleModify" );
- if ( size_t( i_nItemPosition ) < aStringItems.size() )
+ OSL_ENSURE( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size(), "UnoControlListBoxModel::impl_handleModify" );
+ if ( o3tl::make_unsigned( i_nItemPosition ) < aStringItems.size() )
{
aStringItems[ i_nItemPosition] = *i_rItemText;
}
diff --git a/tools/source/stream/stream.cxx b/tools/source/stream/stream.cxx
index 8c38d862b3df..404b9eb67537 100644
--- a/tools/source/stream/stream.cxx
+++ b/tools/source/stream/stream.cxx
@@ -28,6 +28,7 @@
#include <string.h>
#include <stdio.h>
+#include <o3tl/safeint.hxx>
#include <osl/endian.h>
#include <osl/diagnose.h>
#include <rtl/strbuf.hxx>
@@ -488,7 +489,7 @@ bool SvStream::ReadLine( OString& rStr, sal_Int32 nMaxBytesToRead )
++n;
}
nTotalLen += j;
- if (nTotalLen > static_cast<std::size_t>(nMaxBytesToRead))
+ if (nTotalLen > o3tl::make_unsigned(nMaxBytesToRead))
{
n -= nTotalLen - nMaxBytesToRead;
nTotalLen = nMaxBytesToRead;
@@ -574,7 +575,7 @@ bool SvStream::ReadUniStringLine( OUString& rStr, sal_Int32 nMaxCodepointsToRead
}
}
nTotalLen += j;
- if (nTotalLen > static_cast<std::size_t>(nMaxCodepointsToRead))
+ if (nTotalLen > o3tl::make_unsigned(nMaxCodepointsToRead))
{
n -= nTotalLen - nMaxCodepointsToRead;
nTotalLen = nMaxCodepointsToRead;
@@ -796,7 +797,7 @@ sal_uInt64 SvStream::SeekRel(sal_Int64 const nPos)
if ( nPos >= 0 )
{
- if (SAL_MAX_UINT64 - nActualPos > static_cast<sal_uInt64>(nPos))
+ if (SAL_MAX_UINT64 - nActualPos > o3tl::make_unsigned(nPos))
nActualPos += nPos;
}
else
@@ -1244,7 +1245,7 @@ std::size_t SvStream::ReadBytes( void* pData, std::size_t nCount )
// check if block is completely within buffer
m_isIoRead = true;
m_isIoWrite = false;
- if (nCount <= static_cast<std::size_t>(m_nBufActualLen - m_nBufActualPos))
+ if (nCount <= o3tl::make_unsigned(m_nBufActualLen - m_nBufActualPos))
{
// => yes
if (nCount != 0)
@@ -1329,7 +1330,7 @@ std::size_t SvStream::WriteBytes( const void* pData, std::size_t nCount )
m_isIoRead = false;
m_isIoWrite = true;
- if (nCount <= static_cast<std::size_t>(m_nBufSize - m_nBufActualPos))
+ if (nCount <= o3tl::make_unsigned(m_nBufSize - m_nBufActualPos))
{
memcpy( m_pBufPos, pData, nCount );
m_nBufActualPos = m_nBufActualPos + static_cast<sal_uInt16>(nCount);
diff --git a/unotools/source/accessibility/accessiblerelationsethelper.cxx b/unotools/source/accessibility/accessiblerelationsethelper.cxx
index 0e2a57773bb1..8f70623435dc 100644
--- a/unotools/source/accessibility/accessiblerelationsethelper.cxx
+++ b/unotools/source/accessibility/accessiblerelationsethelper.cxx
@@ -20,6 +20,7 @@
#include <sal/config.h>
#include <com/sun/star/lang/IndexOutOfBoundsException.hpp>
+#include <o3tl/safeint.hxx>
#include <unotools/accessiblerelationsethelper.hxx>
#include <vector>
#include <comphelper/sequence.hxx>
@@ -66,7 +67,7 @@ sal_Int32 AccessibleRelationSetHelperImpl::getRelationCount() const
AccessibleRelation const & AccessibleRelationSetHelperImpl::getRelation( sal_Int32 nIndex ) const
{
- if ((nIndex < 0) || (static_cast<sal_uInt32>(nIndex) >= maRelations.size()))
+ if ((nIndex < 0) || (o3tl::make_unsigned(nIndex) >= maRelations.size()))
throw lang::IndexOutOfBoundsException();
return maRelations[nIndex];
}
diff --git a/unotools/source/streaming/streamhelper.cxx b/unotools/source/streaming/streamhelper.cxx
index 1b639fb04825..cf5930d43f19 100644
--- a/unotools/source/streaming/streamhelper.cxx
+++ b/unotools/source/streaming/streamhelper.cxx
@@ -22,6 +22,7 @@
#include <com/sun/star/io/BufferSizeExceededException.hpp>
#include <com/sun/star/io/IOException.hpp>
#include <com/sun/star/io/NotConnectedException.hpp>
+#include <o3tl/safeint.hxx>
#include <unotools/streamhelper.hxx>
namespace utl
@@ -47,7 +48,7 @@ sal_Int32 SAL_CALL OInputStreamHelper::readBytes(css::uno::Sequence< sal_Int8 >&
throw css::io::IOException(OUString(), static_cast<css::uno::XWeak*>(this));
// adjust sequence if data read is lower than the desired data
- if (nRead < static_cast<std::size_t>(aData.getLength()))
+ if (nRead < o3tl::make_unsigned(aData.getLength()))
aData.realloc( nRead );
return nRead;
diff --git a/unotools/source/streaming/streamwrap.cxx b/unotools/source/streaming/streamwrap.cxx
index c24fa09015c1..b2d842f81ff5 100644
--- a/unotools/source/streaming/streamwrap.cxx
+++ b/unotools/source/streaming/streamwrap.cxx
@@ -21,6 +21,7 @@
#include <com/sun/star/io/BufferSizeExceededException.hpp>
#include <com/sun/star/io/NotConnectedException.hpp>
+#include <o3tl/safeint.hxx>
#include <unotools/streamwrap.hxx>
#include <tools/stream.hxx>
@@ -71,7 +72,7 @@ sal_Int32 SAL_CALL OInputStreamWrapper::readBytes(css::uno::Sequence< sal_Int8 >
checkError();
// If read characters < MaxLength, adjust css::uno::Sequence
- if (nRead < static_cast<std::size_t>(aData.getLength()))
+ if (nRead < o3tl::make_unsigned(aData.getLength()))
aData.realloc( nRead );
return nRead;
diff --git a/unotools/source/ucbhelper/xtempfile.cxx b/unotools/source/ucbhelper/xtempfile.cxx
index 24213db368a8..0bd03b6b052f 100644
--- a/unotools/source/ucbhelper/xtempfile.cxx
+++ b/unotools/source/ucbhelper/xtempfile.cxx
@@ -24,6 +24,7 @@
#include <com/sun/star/beans/PropertyAttribute.hpp>
#include <cppuhelper/typeprovider.hxx>
#include <comphelper/servicedecl.hxx>
+#include <o3tl/safeint.hxx>
#include <unotools/tempfile.hxx>
#include <cppuhelper/propshlp.hxx>
@@ -124,7 +125,7 @@ sal_Int32 SAL_CALL OTempFileService::readBytes( css::uno::Sequence< sal_Int8 >&
sal_uInt32 nRead = mpStream->ReadBytes(static_cast<void*>(aData.getArray()), nBytesToRead);
checkError();
- if (nRead < static_cast<std::size_t>(aData.getLength()))
+ if (nRead < o3tl::make_unsigned(aData.getLength()))
aData.realloc( nRead );
if ( sal::static_int_cast<sal_uInt32>(nBytesToRead) > nRead )
diff --git a/unoxml/source/dom/elementlist.cxx b/unoxml/source/dom/elementlist.cxx
index c72e67a10f21..7379ebe1104b 100644
--- a/unoxml/source/dom/elementlist.cxx
+++ b/unoxml/source/dom/elementlist.cxx
@@ -22,6 +22,7 @@
#include <string.h>
#include <cppuhelper/implbase.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/diagnose_ex.h>
#include "element.hxx"
@@ -171,7 +172,7 @@ namespace DOM
if (!m_pElement.is()) { return nullptr; }
buildlist(m_pElement->GetNodePtr());
- if (m_nodevector.size() <= static_cast<size_t>(index)) {
+ if (m_nodevector.size() <= o3tl::make_unsigned(index)) {
throw RuntimeException();
}
Reference< XNode > const xRet(
diff --git a/vbahelper/source/vbahelper/vbadocumentsbase.cxx b/vbahelper/source/vbahelper/vbadocumentsbase.cxx
index d0951b0c13e7..e0f36fb3b137 100644
--- a/vbahelper/source/vbahelper/vbadocumentsbase.cxx
+++ b/vbahelper/source/vbahelper/vbadocumentsbase.cxx
@@ -38,6 +38,7 @@
#include <com/sun/star/lang/XServiceInfo.hpp>
#include <sfx2/objsh.hxx>
#include <tools/urlobj.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/file.hxx>
#include <unordered_map>
@@ -154,7 +155,7 @@ public:
virtual uno::Any SAL_CALL getByIndex( ::sal_Int32 Index ) override
{
if ( Index < 0
- || static_cast< Documents::size_type >(Index) >= m_documents.size() )
+ || o3tl::make_unsigned(Index) >= m_documents.size() )
throw lang::IndexOutOfBoundsException();
return makeAny( m_documents[ Index ] ); // returns xspreadsheetdoc
}
diff --git a/vcl/inc/listbox.hxx b/vcl/inc/listbox.hxx
index f0b4d855e4f4..79b3fa1f5191 100644
--- a/vcl/inc/listbox.hxx
+++ b/vcl/inc/listbox.hxx
@@ -20,6 +20,9 @@
#ifndef INCLUDED_VCL_INC_LISTBOX_HXX
#define INCLUDED_VCL_INC_LISTBOX_HXX
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <vcl/button.hxx>
#include <vcl/floatwin.hxx>
#include <vcl/quickselectionengine.hxx>
@@ -96,7 +99,7 @@ private:
ImplEntryType* GetEntry( sal_Int32 nPos ) const
{
- if (nPos < 0 || static_cast<size_t>(nPos) >= maEntries.size())
+ if (nPos < 0 || o3tl::make_unsigned(nPos) >= maEntries.size())
return nullptr;
return maEntries[nPos].get();
}
diff --git a/vcl/qt5/Qt5Menu.cxx b/vcl/qt5/Qt5Menu.cxx
index d66dc72fd916..b2e752faedaa 100644
--- a/vcl/qt5/Qt5Menu.cxx
+++ b/vcl/qt5/Qt5Menu.cxx
@@ -17,6 +17,7 @@
#include <QtWidgets/QMenuBar>
#include <QtWidgets/QPushButton>
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <sal/log.hxx>
@@ -55,7 +56,7 @@ void Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
pSalMenuItem->mpMenu.reset(pQMenu);
if ((nPos != MENU_APPEND)
- && (static_cast<size_t>(nPos) < static_cast<size_t>(mpQMenuBar->actions().size())))
+ && (static_cast<size_t>(nPos) < o3tl::make_unsigned(mpQMenuBar->actions().size())))
{
mpQMenuBar->insertMenu(mpQMenuBar->actions()[nPos], pQMenu);
}
@@ -85,7 +86,7 @@ void Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
pSalMenuItem->mpMenu.reset(pQMenu);
if ((nPos != MENU_APPEND)
- && (static_cast<size_t>(nPos) < static_cast<size_t>(mpQMenu->actions().size())))
+ && (static_cast<size_t>(nPos) < o3tl::make_unsigned(mpQMenu->actions().size())))
{
mpQMenu->insertMenu(mpQMenu->actions()[nPos], pQMenu);
}
@@ -116,7 +117,7 @@ void Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
pAction->setSeparator(true);
if ((nPos != MENU_APPEND)
- && (static_cast<size_t>(nPos) < static_cast<size_t>(mpQMenu->actions().size())))
+ && (static_cast<size_t>(nPos) < o3tl::make_unsigned(mpQMenu->actions().size())))
{
mpQMenu->insertAction(mpQMenu->actions()[nPos], pAction);
}
@@ -134,7 +135,7 @@ void Qt5Menu::InsertMenuItem(Qt5MenuItem* pSalMenuItem, unsigned nPos)
pSalMenuItem->mpAction.reset(pAction);
if ((nPos != MENU_APPEND)
- && (static_cast<size_t>(nPos) < static_cast<size_t>(mpQMenu->actions().size())))
+ && (static_cast<size_t>(nPos) < o3tl::make_unsigned(mpQMenu->actions().size())))
{
mpQMenu->insertAction(mpQMenu->actions()[nPos], pAction);
}
diff --git a/vcl/source/app/salvtables.cxx b/vcl/source/app/salvtables.cxx
index 687c0d63723a..46f2f070e3ca 100644
--- a/vcl/source/app/salvtables.cxx
+++ b/vcl/source/app/salvtables.cxx
@@ -19,6 +19,7 @@
#include <com/sun/star/accessibility/AccessibleRelationType.hpp>
#include <com/sun/star/awt/XWindow.hpp>
+#include <o3tl/safeint.hxx>
#include <officecfg/Office/Common.hxx>
#include <iconview.hxx>
#include <salframe.hxx>
@@ -3557,7 +3558,7 @@ struct SalInstanceTreeIter : public weld::TreeIter
if (static_cast<size_t>(col) == pEntry->ItemCount())
return TRISTATE_FALSE;
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxButton*>(&rItem));
SvLBoxButton& rToggle = static_cast<SvLBoxButton&>(rItem);
@@ -3572,7 +3573,7 @@ struct SalInstanceTreeIter : public weld::TreeIter
{
++col; //skip dummy/expander column
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxString*>(&rItem));
return static_cast<SvLBoxString&>(rItem).IsEmphasized();
@@ -4004,7 +4005,7 @@ public:
if (static_cast<size_t>(col) == pEntry->ItemCount())
return OUString();
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxString*>(&rItem));
return static_cast<SvLBoxString&>(rItem).GetText();
@@ -4038,7 +4039,7 @@ public:
}
else
{
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxString*>(&rItem));
static_cast<SvLBoxString&>(rItem).SetText(rText);
@@ -4072,7 +4073,7 @@ public:
++col; //skip dummy/expander column
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
rItem.Enable(bSensitive);
@@ -4141,7 +4142,7 @@ public:
m_xTreeView->CheckBoxInserted(pEntry);
}
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxButton*>(&rItem));
switch (eState)
@@ -4176,7 +4177,7 @@ public:
{
++col; //skip dummy/expander column
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxString*>(&rItem));
static_cast<SvLBoxString&>(rItem).Emphasize(bOn);
@@ -4249,7 +4250,7 @@ public:
}
else
{
- assert(col >= 0 && static_cast<size_t>(col) < pEntry->ItemCount());
+ assert(col >= 0 && o3tl::make_unsigned(col) < pEntry->ItemCount());
SvLBoxItem& rItem = pEntry->GetItem(col);
assert(dynamic_cast<SvLBoxContextBmp*>(&rItem));
static_cast<SvLBoxContextBmp&>(rItem).SetBitmap1(rImage);
diff --git a/vcl/source/control/edit.cxx b/vcl/source/control/edit.cxx
index 72c09a1e522a..a8a2cbe6f833 100644
--- a/vcl/source/control/edit.cxx
+++ b/vcl/source/control/edit.cxx
@@ -59,7 +59,7 @@
#include <i18nlangtag/languagetag.hxx>
#include <vcl/unohelp2.hxx>
-
+#include <o3tl/safeint.hxx>
#include <officecfg/Office/Common.hxx>
#include <memory>
@@ -471,7 +471,7 @@ void Edit::ImplRepaint(vcl::RenderContext& rRenderContext, const tools::Rectangl
if (nLen)
{
- if (static_cast<size_t>(2 * nLen) > SAL_N_ELEMENTS(nDXBuffer))
+ if (o3tl::make_unsigned(2 * nLen) > SAL_N_ELEMENTS(nDXBuffer))
{
pDXBuffer.reset(new long[2 * (nLen + 1)]);
pDX = pDXBuffer.get();
@@ -1060,7 +1060,7 @@ void Edit::ImplShowCursor( bool bOnlyIfVisible )
if( !aText.isEmpty() )
{
- if( static_cast<size_t>(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
+ if( o3tl::make_unsigned(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
{
pDXBuffer.reset(new long[2*(aText.getLength()+1)]);
pDX = pDXBuffer.get();
@@ -1181,7 +1181,7 @@ sal_Int32 Edit::ImplGetCharPos( const Point& rWindowPos ) const
long nDXBuffer[256];
std::unique_ptr<long[]> pDXBuffer;
long* pDX = nDXBuffer;
- if( static_cast<size_t>(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
+ if( o3tl::make_unsigned(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
{
pDXBuffer.reset(new long[2*(aText.getLength()+1)]);
pDX = pDXBuffer.get();
@@ -2112,7 +2112,7 @@ void Edit::Command( const CommandEvent& rCEvt )
if( !aText.isEmpty() )
{
- if( static_cast<size_t>(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
+ if( o3tl::make_unsigned(2*aText.getLength()) > SAL_N_ELEMENTS(nDXBuffer) )
{
pDXBuffer.reset(new long[2*(aText.getLength()+1)]);
pDX = pDXBuffer.get();
diff --git a/vcl/source/control/imivctl.hxx b/vcl/source/control/imivctl.hxx
index be3a6ea287c2..a2765a95aea9 100644
--- a/vcl/source/control/imivctl.hxx
+++ b/vcl/source/control/imivctl.hxx
@@ -20,6 +20,9 @@
#ifndef INCLUDED_SVTOOLS_SOURCE_CONTNR_IMIVCTL_HXX
#define INCLUDED_SVTOOLS_SOURCE_CONTNR_IMIVCTL_HXX
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <vcl/ivctrl.hxx>
#include <vcl/virdev.hxx>
#include <vcl/scrbar.hxx>
@@ -490,8 +493,8 @@ public:
void OccupyGrids( const SvxIconChoiceCtrlEntry* );
void OccupyGrid( GridId nId )
{
- DBG_ASSERT(!_pGridMap || nId<static_cast<sal_uLong>(_nGridCols*_nGridRows),"OccupyGrid: Bad GridId");
- if(_pGridMap && nId < static_cast<sal_uLong>(_nGridCols *_nGridRows) )
+ DBG_ASSERT(!_pGridMap || nId<o3tl::make_unsigned(_nGridCols*_nGridRows),"OccupyGrid: Bad GridId");
+ if(_pGridMap && nId < o3tl::make_unsigned(_nGridCols *_nGridRows) )
_pGridMap[ nId ] = true;
}
diff --git a/vcl/source/control/imivctl2.cxx b/vcl/source/control/imivctl2.cxx
index f7d2d787f864..284921f8f62e 100644
--- a/vcl/source/control/imivctl2.cxx
+++ b/vcl/source/control/imivctl2.cxx
@@ -597,7 +597,7 @@ GridId IcnGridMap_Impl::GetGrid( const Point& rDocPos )
nY = _nGridRows - 1;
}
GridId nId = GetGrid( static_cast<sal_uInt16>(nX), static_cast<sal_uInt16>(nY) );
- DBG_ASSERT(nId <static_cast<sal_uLong>(_nGridCols*_nGridRows),"GetGrid failed");
+ DBG_ASSERT(nId <o3tl::make_unsigned(_nGridCols*_nGridRows),"GetGrid failed");
return nId;
}
diff --git a/vcl/source/control/imp_listbox.cxx b/vcl/source/control/imp_listbox.cxx
index c65f63b4b782..8e912aeda4f2 100644
--- a/vcl/source/control/imp_listbox.cxx
+++ b/vcl/source/control/imp_listbox.cxx
@@ -35,6 +35,7 @@
#include <rtl/instance.hxx>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <comphelper/string.hxx>
#include <comphelper/processfactory.hxx>
@@ -81,7 +82,7 @@ void ImplEntryList::Clear()
void ImplEntryList::SelectEntry( sal_Int32 nPos, bool bSelect )
{
- if (0 <= nPos && static_cast<size_t>(nPos) < maEntries.size())
+ if (0 <= nPos && o3tl::make_unsigned(nPos) < maEntries.size())
{
std::vector<std::unique_ptr<ImplEntryType> >::iterator iter = maEntries.begin()+nPos;
@@ -218,7 +219,7 @@ sal_Int32 ImplEntryList::InsertEntry( sal_Int32 nPos, ImplEntryType* pNewEntry,
void ImplEntryList::RemoveEntry( sal_Int32 nPos )
{
- if (0 <= nPos && static_cast<size_t>(nPos) < maEntries.size())
+ if (0 <= nPos && o3tl::make_unsigned(nPos) < maEntries.size())
{
std::vector<std::unique_ptr<ImplEntryType> >::iterator iter = maEntries.begin()+ nPos;
diff --git a/vcl/source/filter/FilterConfigCache.cxx b/vcl/source/filter/FilterConfigCache.cxx
index 0ed0a431e235..5321ea2599c5 100644
--- a/vcl/source/filter/FilterConfigCache.cxx
+++ b/vcl/source/filter/FilterConfigCache.cxx
@@ -19,6 +19,7 @@
#include "FilterConfigCache.hxx"
+#include <o3tl/safeint.hxx>
#include <vcl/graphicfilter.hxx>
#include <unotools/configmgr.hxx>
#include <tools/svlibrary.h>
@@ -380,7 +381,7 @@ OUString FilterConfigCache::GetImportFormatShortName( sal_uInt16 nFormat )
OUString FilterConfigCache::GetImportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry )
{
- if ( (nFormat < aImport.size()) && (size_t(nEntry) < aImport[ nFormat ].lExtensionList.size()) )
+ if ( (nFormat < aImport.size()) && (o3tl::make_unsigned(nEntry) < aImport[ nFormat ].lExtensionList.size()) )
return aImport[ nFormat ].lExtensionList[ nEntry ];
return OUString();
}
@@ -505,7 +506,7 @@ OUString FilterConfigCache::GetExportFormatShortName( sal_uInt16 nFormat )
OUString FilterConfigCache::GetExportFormatExtension( sal_uInt16 nFormat, sal_Int32 nEntry )
{
- if ( (nFormat < aExport.size()) && (size_t(nEntry) < aExport[ nFormat ].lExtensionList.size()) )
+ if ( (nFormat < aExport.size()) && (o3tl::make_unsigned(nEntry) < aExport[ nFormat ].lExtensionList.size()) )
return aExport[ nFormat ].lExtensionList[ nEntry ];
return OUString();
}
diff --git a/vcl/source/fontsubset/cff.cxx b/vcl/source/fontsubset/cff.cxx
index 2698b22b54bc..959b59668f62 100644
--- a/vcl/source/fontsubset/cff.cxx
+++ b/vcl/source/fontsubset/cff.cxx
@@ -24,6 +24,7 @@
#include <fontsubset.hxx>
+#include <o3tl/safeint.hxx>
#include <vcl/strhelper.hxx>
#include <sal/log.hxx>
@@ -1368,7 +1369,7 @@ bool CffSubsetterContext::initialCffRead()
// assert( mnFontDictBase == tellRel());
mpReadPtr = mpBasePtr + mnFontDictBase;
mnFDAryCount = (mpReadPtr[0]<<8) + mpReadPtr[1];
- if (static_cast<size_t>(mnFDAryCount) >= SAL_N_ELEMENTS(maCffLocal))
+ if (o3tl::make_unsigned(mnFDAryCount) >= SAL_N_ELEMENTS(maCffLocal))
{
SAL_INFO("vcl.fonts", "CffSubsetterContext: too many CFF in font");
return false;
diff --git a/vcl/source/gdi/dibtools.cxx b/vcl/source/gdi/dibtools.cxx
index 6c29bc325397..b061da93022d 100644
--- a/vcl/source/gdi/dibtools.cxx
+++ b/vcl/source/gdi/dibtools.cxx
@@ -22,6 +22,7 @@
#include <cassert>
+#include <o3tl/safeint.hxx>
#include <vcl/dibtools.hxx>
#include <comphelper/fileformat.h>
#include <tools/zcodec.hxx>
@@ -276,7 +277,7 @@ bool ImplReadDIBInfoHeader(SvStream& rIStm, DIBV5Header& rHeader, bool& bTopDown
assert(rHeader.nHeight >= 0);
if (rHeader.nHeight != 0 && rHeader.nWidth >= 0
&& (rHeader.nSizeImage / 16 / static_cast<sal_uInt32>(rHeader.nHeight)
- > static_cast<sal_uInt32>(rHeader.nWidth)))
+ > o3tl::make_unsigned(rHeader.nWidth)))
{
rHeader.nSizeImage = 0;
}
@@ -929,7 +930,7 @@ bool ImplReadDIBBody(SvStream& rIStm, Bitmap& rBmp, AlphaMask* pBmpAlpha, sal_uL
sal_uInt64 nMaxWidth = pIStm->remainingSize();
nMaxWidth *= 256; //assume generous compression ratio
nMaxWidth /= aHeader.nHeight;
- if (nMaxWidth < static_cast<sal_uInt64>(aHeader.nWidth))
+ if (nMaxWidth < o3tl::make_unsigned(aHeader.nWidth))
return false;
break;
}
@@ -940,7 +941,7 @@ bool ImplReadDIBBody(SvStream& rIStm, Bitmap& rBmp, AlphaMask* pBmpAlpha, sal_uL
sal_uInt64 nMaxWidth = pIStm->remainingSize();
nMaxWidth *= 512; //assume generous compression ratio
nMaxWidth /= aHeader.nHeight;
- if (nMaxWidth < static_cast<sal_uInt64>(aHeader.nWidth))
+ if (nMaxWidth < o3tl::make_unsigned(aHeader.nWidth))
return false;
break;
}
diff --git a/vcl/source/gdi/pdfextoutdevdata.cxx b/vcl/source/gdi/pdfextoutdevdata.cxx
index e36cb0e9ceef..e46396e73f7a 100644
--- a/vcl/source/gdi/pdfextoutdevdata.cxx
+++ b/vcl/source/gdi/pdfextoutdevdata.cxx
@@ -27,6 +27,7 @@
#include <basegfx/polygon/b2dpolygon.hxx>
#include <basegfx/polygon/b2dpolygontools.hxx>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tools/stream.hxx>
@@ -121,7 +122,7 @@ sal_Int32 GlobalSyncData::GetMappedId()
*/
if( nLinkId >= 0 )
{
- if ( static_cast<sal_uInt32>(nLinkId) < mParaIds.size() )
+ if ( o3tl::make_unsigned(nLinkId) < mParaIds.size() )
nLinkId = mParaIds[ nLinkId ];
else
nLinkId = -1;
@@ -134,7 +135,7 @@ sal_Int32 GlobalSyncData::GetMappedId()
sal_Int32 GlobalSyncData::GetMappedStructId( sal_Int32 nStructId )
{
- if ( static_cast<sal_uInt32>(nStructId) < mStructIdMap.size() )
+ if ( o3tl::make_unsigned(nStructId) < mStructIdMap.size() )
nStructId = mStructIdMap[ nStructId ];
else
nStructId = -1;
@@ -753,7 +754,7 @@ void PDFExtOutDevData::EndStructureElement()
bool PDFExtOutDevData::SetCurrentStructureElement( sal_Int32 nStructId )
{
bool bSuccess = false;
- if( sal_uInt32(nStructId) < mpGlobalSyncData->mStructParents.size() )
+ if( o3tl::make_unsigned(nStructId) < mpGlobalSyncData->mStructParents.size() )
{
mpGlobalSyncData->mCurrentStructElement = nStructId;
mpPageSyncData->PushAction( mrOutDev, PDFExtOutDevDataSync::SetCurrentStructureElement );
diff --git a/vcl/source/gdi/pdfwriter_impl.hxx b/vcl/source/gdi/pdfwriter_impl.hxx
index 82afd47e850e..c70628ab1789 100644
--- a/vcl/source/gdi/pdfwriter_impl.hxx
+++ b/vcl/source/gdi/pdfwriter_impl.hxx
@@ -44,6 +44,7 @@
#include <vcl/virdev.hxx>
#include <vcl/pdfwriter.hxx>
#include <vcl/wall.hxx>
+#include <o3tl/safeint.hxx>
#include <o3tl/typed_flags_set.hxx>
#include <comphelper/hash.hxx>
#include <tools/stream.hxx>
@@ -287,7 +288,7 @@ public:
sal_Ucs getCode( sal_Int32 i_nIndex ) const
{
sal_Ucs nRet = 0;
- if (static_cast<size_t>(i_nIndex) < m_CodeUnits.size())
+ if (o3tl::make_unsigned(i_nIndex) < m_CodeUnits.size())
nRet = m_CodeUnits[i_nIndex];
return nRet;
}
diff --git a/vcl/source/gdi/svmconverter.cxx b/vcl/source/gdi/svmconverter.cxx
index dc48dea5c718..d65b6c52f796 100644
--- a/vcl/source/gdi/svmconverter.cxx
+++ b/vcl/source/gdi/svmconverter.cxx
@@ -19,6 +19,8 @@
#include <algorithm>
#include <string.h>
+
+#include <o3tl/safeint.hxx>
#include <osl/thread.h>
#include <tools/fract.hxx>
#include <tools/stream.hxx>
@@ -330,7 +332,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
const size_t nMinActionSize = sizeof(sal_uInt16) + sizeof(sal_Int32);
const size_t nMaxPossibleActions = rIStm.remainingSize() / nMinActionSize;
- if (static_cast<sal_uInt32>(nActions) > nMaxPossibleActions)
+ if (o3tl::make_unsigned(nActions) > nMaxPossibleActions)
{
SAL_WARN("vcl.gdi", "svm claims more actions (" << nActions << ") than stream could provide, truncating");
nActions = nMaxPossibleActions;
@@ -717,7 +719,7 @@ void SVMConverter::ImplConvertFromSVM1( SvStream& rIStm, GDIMetaFile& rMtf )
{
const size_t nMinRecordSize = sizeof(sal_Int32);
const size_t nMaxRecords = rIStm.remainingSize() / nMinRecordSize;
- if (static_cast<sal_uInt32>(nAryLen) > nMaxRecords)
+ if (o3tl::make_unsigned(nAryLen) > nMaxRecords)
{
SAL_WARN("vcl.gdi", "Parsing error: " << nMaxRecords <<
" max possible entries, but " << nAryLen << " claimed, truncating");
diff --git a/vcl/source/treelist/svimpbox.cxx b/vcl/source/treelist/svimpbox.cxx
index 0c3a2ef5bae0..6ae3daf0346c 100644
--- a/vcl/source/treelist/svimpbox.cxx
+++ b/vcl/source/treelist/svimpbox.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <vcl/svapp.hxx>
#include <vcl/salnativewidgets.hxx>
#include <vcl/help.hxx>
@@ -219,7 +222,7 @@ void SvImpLBox::CalcCellFocusRect( tools::Rectangle& rRect )
SvLBoxItem& rItem = m_pCursor->GetItem( m_nCurTabPos );
rRect.SetLeft( m_pView->GetTab( m_pCursor, &rItem )->GetPos() );
}
- if (m_pCursor->ItemCount() > static_cast<size_t>(m_nCurTabPos+1))
+ if (m_pCursor->ItemCount() > o3tl::make_unsigned(m_nCurTabPos+1))
{
SvLBoxItem& rNextItem = m_pCursor->GetItem( m_nCurTabPos + 1 );
long nRight = m_pView->GetTab( m_pCursor, &rNextItem )->GetPos() - 1;
@@ -1315,7 +1318,7 @@ void SvImpLBox::FillView()
long nTempThumb = m_aVerSBar->GetThumbPos();
if( nTempThumb < 0 )
nTempThumb = 0;
- else if( static_cast<unsigned long>(nTempThumb) >= nVisibleViewCount )
+ else if( o3tl::make_unsigned(nTempThumb) >= nVisibleViewCount )
nTempThumb = nVisibleViewCount == 0 ? 0 : nVisibleViewCount - 1;
m_pStartEntry = m_pView->GetEntryAtVisPos(nTempThumb);
}
diff --git a/vcl/source/treelist/svtabbx.cxx b/vcl/source/treelist/svtabbx.cxx
index 809f0885be4d..f573dbd2bd8a 100644
--- a/vcl/source/treelist/svtabbx.cxx
+++ b/vcl/source/treelist/svtabbx.cxx
@@ -26,6 +26,7 @@
#include <unotools/accessiblestatesethelper.hxx>
#include <com/sun/star/accessibility/AccessibleStateType.hpp>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <strings.hrc>
#include <svdata.hxx>
@@ -298,7 +299,7 @@ OUString SvTabListBox::GetCellText( sal_uLong nPos, sal_uInt16 nCol ) const
SvTreeListEntry* pEntry = GetEntryOnPos( nPos );
DBG_ASSERT( pEntry, "SvTabListBox::GetCellText(): Invalid Entry" );
OUString aResult;
- if (pEntry && pEntry->ItemCount() > static_cast<size_t>(nCol+1))
+ if (pEntry && pEntry->ItemCount() > o3tl::make_unsigned(nCol+1))
{
const SvLBoxItem& rStr = pEntry->GetItem( nCol + 1 );
if (rStr.GetType() == SvLBoxItemType::String)
diff --git a/vcl/source/window/syswin.cxx b/vcl/source/window/syswin.cxx
index 5dbcd6852859..3c154dd228c7 100644
--- a/vcl/source/window/syswin.cxx
+++ b/vcl/source/window/syswin.cxx
@@ -18,6 +18,8 @@
*/
#include <memory>
+
+#include <o3tl/safeint.hxx>
#include <sal/config.h>
#include <sal/log.hxx>
@@ -705,15 +707,15 @@ void SystemWindow::SetWindowStateData( const WindowStateData& rData )
if( std::abs(g.nX-aState.mnX) < 2 && std::abs(g.nY-aState.mnY) < 5 )
{
long displacement = g.nTopDecoration ? g.nTopDecoration : 20;
- if( aState.mnX + displacement + aState.mnWidth + g.nRightDecoration > static_cast<unsigned long>(aDesktop.Right()) ||
- aState.mnY + displacement + aState.mnHeight + g.nBottomDecoration > static_cast<unsigned long>(aDesktop.Bottom()) )
+ if( aState.mnX + displacement + aState.mnWidth + g.nRightDecoration > o3tl::make_unsigned(aDesktop.Right()) ||
+ aState.mnY + displacement + aState.mnHeight + g.nBottomDecoration > o3tl::make_unsigned(aDesktop.Bottom()) )
{
// displacing would leave screen
aState.mnX = g.nLeftDecoration ? g.nLeftDecoration : 10; // should result in (0,0)
aState.mnY = displacement;
if( bWrapped ||
- aState.mnX + displacement + aState.mnWidth + g.nRightDecoration > static_cast<unsigned long>(aDesktop.Right()) ||
- aState.mnY + displacement + aState.mnHeight + g.nBottomDecoration > static_cast<unsigned long>(aDesktop.Bottom()) )
+ aState.mnX + displacement + aState.mnWidth + g.nRightDecoration > o3tl::make_unsigned(aDesktop.Right()) ||
+ aState.mnY + displacement + aState.mnHeight + g.nBottomDecoration > o3tl::make_unsigned(aDesktop.Bottom()) )
break; // further displacement not possible -> break
// avoid endless testing
bWrapped = true;
diff --git a/vcl/source/window/winproc.cxx b/vcl/source/window/winproc.cxx
index fc50ffe45567..50116e908559 100644
--- a/vcl/source/window/winproc.cxx
+++ b/vcl/source/window/winproc.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <tools/debug.hxx>
#include <tools/time.hxx>
#include <sal/log.hxx>
@@ -2336,7 +2339,7 @@ static void ImplHandleSalQueryCharPosition( vcl::Window *pWindow,
ImplCallCommand( pChild, CommandEventId::QueryCharPosition );
ImplWinData* pWinData = pChild->ImplGetWinData();
- if ( pWinData->mpCompositionCharRects && pEvt->mnCharPos < static_cast<sal_uLong>( pWinData->mnCompositionCharRects ) )
+ if ( pWinData->mpCompositionCharRects && pEvt->mnCharPos < o3tl::make_unsigned( pWinData->mnCompositionCharRects ) )
{
const OutputDevice *pChildOutDev = pChild->GetOutDev();
const tools::Rectangle& aRect = pWinData->mpCompositionCharRects[ pEvt->mnCharPos ];
diff --git a/vcl/unx/generic/app/i18n_cb.cxx b/vcl/unx/generic/app/i18n_cb.cxx
index 5d3ba88eb782..b6c6326879fd 100644
--- a/vcl/unx/generic/app/i18n_cb.cxx
+++ b/vcl/unx/generic/app/i18n_cb.cxx
@@ -20,6 +20,7 @@
#include <stdio.h>
#include <string.h>
+#include <o3tl/safeint.hxx>
#include <osl/thread.h>
#include <X11/Xlib.h>
@@ -114,7 +115,7 @@ enlarge_buffer ( preedit_text_t *ptext, int nnewlimit )
{
size_t nnewsize = ptext->nSize;
- while ( nnewsize <= static_cast<size_t>(nnewlimit) )
+ while ( nnewsize <= o3tl::make_unsigned(nnewlimit) )
nnewsize *= 2;
ptext->nSize = nnewsize;
diff --git a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
index a4f9fce70e94..956ce000a6b8 100644
--- a/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
+++ b/vcl/unx/generic/glyphs/freetype_glyphcache.cxx
@@ -17,7 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+#include <o3tl/safeint.hxx>
#include <vcl/fontcharmap.hxx>
#include <unx/freetype_glyphcache.hxx>
@@ -181,7 +183,7 @@ FT_FaceRec_* FreetypeFontInfo::GetFaceFT()
FT_MM_Var *pFtMMVar;
if (FT_Get_MM_Var(maFaceFT, &pFtMMVar) == 0)
{
- if (static_cast<sal_uInt32>(mnFaceVariation) <= pFtMMVar->num_namedstyles)
+ if (o3tl::make_unsigned(mnFaceVariation) <= pFtMMVar->num_namedstyles)
{
FT_Var_Named_Style *instance = &pFtMMVar->namedstyle[mnFaceVariation - 1];
FT_Set_Var_Design_Coordinates(maFaceFT, pFtMMVar->num_axis, instance->coords);
diff --git a/vcl/unx/generic/printer/ppdparser.cxx b/vcl/unx/generic/printer/ppdparser.cxx
index c1f61fae7794..ec9960eab94b 100644
--- a/vcl/unx/generic/printer/ppdparser.cxx
+++ b/vcl/unx/generic/printer/ppdparser.cxx
@@ -36,6 +36,7 @@
#include <tools/urlobj.hxx>
#include <tools/stream.hxx>
#include <tools/zcodec.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/mutex.hxx>
#include <osl/file.hxx>
#include <osl/process.h>
@@ -885,7 +886,7 @@ void PPDParser::insertKey( std::unique_ptr<PPDKey> pKey )
const PPDKey* PPDParser::getKey( int n ) const
{
- return (static_cast<unsigned int>(n) < m_aOrderedKeys.size() && n >= 0) ? m_aOrderedKeys[n] : nullptr;
+ return (n >= 0 && o3tl::make_unsigned(n) < m_aOrderedKeys.size()) ? m_aOrderedKeys[n] : nullptr;
}
const PPDKey* PPDParser::getKey( const OUString& rKey ) const
@@ -1581,7 +1582,7 @@ PPDKey::~PPDKey()
const PPDValue* PPDKey::getValue( int n ) const
{
- return (static_cast<unsigned int>(n) < m_aOrderedValues.size() && n >= 0) ? m_aOrderedValues[n] : nullptr;
+ return (n >= 0 && o3tl::make_unsigned(n) < m_aOrderedValues.size()) ? m_aOrderedValues[n] : nullptr;
}
const PPDValue* PPDKey::getValue( const OUString& rOption ) const
@@ -1650,7 +1651,7 @@ PPDContext& PPDContext::operator=( PPDContext&& rCopy )
const PPDKey* PPDContext::getModifiedKey( int n ) const
{
assert(n >= 0);
- if( m_aCurrentValues.size() <= static_cast<hash_type::size_type>(n) )
+ if( m_aCurrentValues.size() <= o3tl::make_unsigned(n) )
return nullptr;
hash_type::const_iterator it = m_aCurrentValues.begin();
diff --git a/vcl/unx/gtk3/gtk3gtkdata.cxx b/vcl/unx/gtk3/gtk3gtkdata.cxx
index 36d4e6d76fa1..912bc52d116b 100644
--- a/vcl/unx/gtk3/gtk3gtkdata.cxx
+++ b/vcl/unx/gtk3/gtk3gtkdata.cxx
@@ -31,6 +31,7 @@
#include <unx/gtk/gtkframe.hxx>
#include <bitmaps.hlst>
#include <cursor_hotspots.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/thread.h>
#include <osl/process.h>
@@ -565,7 +566,7 @@ extern "C" {
nDeltaSec -= 1;
}
// if the clock changes backwards we need to cope ...
- if( static_cast<unsigned long>(nDeltaSec) > 1 + ( pTSource->pInstance->m_nTimeoutMS / 1000 ) )
+ if( o3tl::make_unsigned(nDeltaSec) > 1 + ( pTSource->pInstance->m_nTimeoutMS / 1000 ) )
{
sal_gtk_timeout_defer( pTSource );
return true;
diff --git a/vcl/workben/vcldemo.cxx b/vcl/workben/vcldemo.cxx
index 97b51bbb8f00..a6ce87ac7a48 100644
--- a/vcl/workben/vcldemo.cxx
+++ b/vcl/workben/vcldemo.cxx
@@ -27,7 +27,7 @@
#include <com/sun/star/uno/Reference.hxx>
#include <com/sun/star/uno/Sequence.hxx>
#include <com/sun/star/container/XNameAccess.hpp>
-
+#include <o3tl/safeint.hxx>
#include <osl/time.h>
#include <vcl/gradient.hxx>
#include <vcl/vclmain.hxx>
@@ -1493,7 +1493,7 @@ public:
if (!bVDev /* want everything in the vdev */ &&
mnSelectedRenderer >= 0 &&
- static_cast<sal_uInt32>(mnSelectedRenderer) < maRenderers.size())
+ o3tl::make_unsigned(mnSelectedRenderer) < maRenderers.size())
{
aCtx.meStyle = RENDER_EXPANDED;
RegionRenderer * r = maRenderers[mnSelectedRenderer];
diff --git a/writerperfect/qa/unit/EPUBExportTest.cxx b/writerperfect/qa/unit/EPUBExportTest.cxx
index edc2da70f59a..f9f821773b18 100644
--- a/writerperfect/qa/unit/EPUBExportTest.cxx
+++ b/writerperfect/qa/unit/EPUBExportTest.cxx
@@ -18,6 +18,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/propertysequence.hxx>
#include <comphelper/string.hxx>
+#include <o3tl/safeint.hxx>
#include <test/bootstrapfixture.hxx>
#include <test/xmltesttools.hxx>
#include <unotest/macros_test.hxx>
@@ -804,7 +805,7 @@ CPPUNIT_TEST_FIXTURE(EPUBExportTest, testSVG)
SvMemoryStream aMemoryStream;
aMemoryStream.WriteStream(*pStream);
OString aExpected("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n\n<svg");
- CPPUNIT_ASSERT(aMemoryStream.GetSize() > static_cast<sal_uInt64>(aExpected.getLength()));
+ CPPUNIT_ASSERT(aMemoryStream.GetSize() > o3tl::make_unsigned(aExpected.getLength()));
// This failed, there was a '<!DOCTYPE' line between the xml and the svg
// one, causing a validation error.
diff --git a/writerperfect/source/common/WPXSvInputStream.cxx b/writerperfect/source/common/WPXSvInputStream.cxx
index 3f37c89c11c3..8118d7860019 100644
--- a/writerperfect/source/common/WPXSvInputStream.cxx
+++ b/writerperfect/source/common/WPXSvInputStream.cxx
@@ -14,7 +14,7 @@
#include <comphelper/processfactory.hxx>
#include <comphelper/seekableinput.hxx>
-
+#include <o3tl/safeint.hxx>
#include <rtl/string.hxx>
#include <sal/log.hxx>
@@ -848,7 +848,7 @@ const unsigned char* WPXSvInputStream::read(unsigned long numBytes, unsigned lon
if ((curpos + numBytes < curpos) /*overflow*/
|| (curpos + numBytes
- >= static_cast<sal_uInt64>(mpImpl->mnLength))) /*reading more than available*/
+ >= o3tl::make_unsigned(mpImpl->mnLength))) /*reading more than available*/
{
numBytes = mpImpl->mnLength - curpos;
}
@@ -909,7 +909,7 @@ int WPXSvInputStream::seek(long offset, librevenge::RVNG_SEEK_TYPE seekType)
}
if (tmpOffset < mpImpl->tell()
- && static_cast<unsigned long>(tmpOffset)
+ && o3tl::make_unsigned(tmpOffset)
>= static_cast<unsigned long>(mpImpl->tell()) - mpImpl->mnReadBufferLength)
{
mpImpl->mnReadBufferPos = static_cast<unsigned long>(
diff --git a/xmlhelp/source/treeview/tvread.cxx b/xmlhelp/source/treeview/tvread.cxx
index e71f24b4f6ad..d43ed0fd416a 100644
--- a/xmlhelp/source/treeview/tvread.cxx
+++ b/xmlhelp/source/treeview/tvread.cxx
@@ -21,6 +21,7 @@
#include <rtl/character.hxx>
#include <rtl/ustrbuf.hxx>
#include <sal/log.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <tvread.hxx>
#include <expat.h>
@@ -506,7 +507,7 @@ TVChildTarget::getByName( const OUString& aName )
{
OUString num( aName.copy( 2, aName.getLength()-4 ) );
sal_Int32 idx = num.toInt32() - 1;
- if( idx < 0 || Elements.size() <= sal_uInt32( idx ) )
+ if( idx < 0 || Elements.size() <= o3tl::make_unsigned( idx ) )
throw NoSuchElementException();
cppu::OWeakObject* p = Elements[idx].get();
@@ -528,7 +529,7 @@ TVChildTarget::hasByName( const OUString& aName )
{
OUString num( aName.copy( 2, aName.getLength()-4 ) );
sal_Int32 idx = num.toInt32() - 1;
- if( idx < 0 || Elements.size() <= sal_uInt32( idx ) )
+ if( idx < 0 || Elements.size() <= o3tl::make_unsigned( idx ) )
return false;
return true;
@@ -546,7 +547,7 @@ TVChildTarget::getByHierarchicalName( const OUString& aName )
OUString num( aName.copy( 2, idx-4 ) );
sal_Int32 pref = num.toInt32() - 1;
- if( pref < 0 || Elements.size() <= sal_uInt32( pref ) )
+ if( pref < 0 || Elements.size() <= o3tl::make_unsigned( pref ) )
throw NoSuchElementException();
return Elements[pref]->getByHierarchicalName( aName.copy( 1 + idx ) );
@@ -564,7 +565,7 @@ TVChildTarget::hasByHierarchicalName( const OUString& aName )
{
OUString num( aName.copy( 2, idx-4 ) );
sal_Int32 pref = num.toInt32() - 1;
- if( pref < 0 || Elements.size() <= sal_uInt32( pref ) )
+ if( pref < 0 || Elements.size() <= o3tl::make_unsigned( pref ) )
return false;
return Elements[pref]->hasByHierarchicalName( aName.copy( 1 + idx ) );
diff --git a/xmloff/source/chart/SchXMLTableContext.cxx b/xmloff/source/chart/SchXMLTableContext.cxx
index 69b738a66688..44d878759fb6 100644
--- a/xmloff/source/chart/SchXMLTableContext.cxx
+++ b/xmloff/source/chart/SchXMLTableContext.cxx
@@ -26,6 +26,7 @@
#include "SchXMLTools.hxx"
#include "transporttypes.hxx"
#include <XMLStringBufferImportContext.hxx>
+#include <o3tl/safeint.hxx>
#include <rtl/math.hxx>
#include <sal/log.hxx>
#include <xmloff/xmlnmspe.hxx>
@@ -521,7 +522,7 @@ SchXMLTableRowContext::SchXMLTableRowContext(
std::vector< SchXMLCell > aNewRow;
aNewRow.reserve( mrTable.nNumberOfColsEstimate );
- while( mrTable.aData.size() <= static_cast<unsigned long>(mrTable.nRowIndex) )
+ while( mrTable.aData.size() <= o3tl::make_unsigned(mrTable.nRowIndex) )
mrTable.aData.push_back( aNewRow );
}
diff --git a/xmloff/source/core/attrlist.cxx b/xmloff/source/core/attrlist.cxx
index 8120fc32d647..c65b9a3cb4b1 100644
--- a/xmloff/source/core/attrlist.cxx
+++ b/xmloff/source/core/attrlist.cxx
@@ -19,6 +19,8 @@
#include <vector>
+
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <xmloff/xmltoken.hxx>
#include <cppuhelper/implbase.hxx>
@@ -88,7 +90,7 @@ SvXMLAttributeList::SvXMLAttributeList( const uno::Reference<
OUString SAL_CALL SvXMLAttributeList::getNameByIndex(sal_Int16 i)
{
- return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sName : OUString();
+ return ( o3tl::make_unsigned( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sName : OUString();
}
@@ -99,7 +101,7 @@ OUString SAL_CALL SvXMLAttributeList::getTypeByIndex(sal_Int16)
OUString SAL_CALL SvXMLAttributeList::getValueByIndex(sal_Int16 i)
{
- return ( static_cast< SvXMLAttributeList_Impl::size_type >( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sValue : OUString();
+ return ( o3tl::make_unsigned( i ) < m_pImpl->vecAttribute.size() ) ? m_pImpl->vecAttribute[i].sValue : OUString();
}
OUString SAL_CALL SvXMLAttributeList::getTypeByName( const OUString& )
@@ -181,7 +183,7 @@ void SvXMLAttributeList::AppendAttributeList( const uno::Reference< css::xml::sa
void SvXMLAttributeList::SetValueByIndex( sal_Int16 i,
const OUString& rValue )
{
- if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
+ if( o3tl::make_unsigned( i )
< m_pImpl->vecAttribute.size() )
{
m_pImpl->vecAttribute[i].sValue = rValue;
@@ -190,7 +192,7 @@ void SvXMLAttributeList::SetValueByIndex( sal_Int16 i,
void SvXMLAttributeList::RemoveAttributeByIndex( sal_Int16 i )
{
- if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
+ if( o3tl::make_unsigned( i )
< m_pImpl->vecAttribute.size() )
m_pImpl->vecAttribute.erase( m_pImpl->vecAttribute.begin() + i );
}
@@ -198,7 +200,7 @@ void SvXMLAttributeList::RemoveAttributeByIndex( sal_Int16 i )
void SvXMLAttributeList::RenameAttributeByIndex( sal_Int16 i,
const OUString& rNewName )
{
- if( static_cast< SvXMLAttributeList_Impl::size_type >( i )
+ if( o3tl::make_unsigned( i )
< m_pImpl->vecAttribute.size() )
{
m_pImpl->vecAttribute[i].sName = rNewName;
diff --git a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
index 82159e0175fc..d2e29422ae1c 100644
--- a/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
+++ b/xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx
@@ -17,6 +17,9 @@
* the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/
+#include <sal/config.h>
+
+#include <o3tl/safeint.hxx>
#include <xmloff/unointerfacetouniqueidentifiermapper.hxx>
using namespace ::com::sun::star;
@@ -159,7 +162,7 @@ void UnoInterfaceToUniqueIdentifierMapper::insertReference( const OUString& rIde
// so we make sure we will never generate
// an integer value like this one
sal_Int32 nId = rIdentifier.copy(2).toInt32();
- if (nId > 0 && mnNextId <= static_cast<sal_uInt32>(nId))
+ if (nId > 0 && mnNextId <= o3tl::make_unsigned(nId))
{
mnNextId = nId;
++mnNextId;
diff --git a/xmloff/source/text/txtlists.cxx b/xmloff/source/text/txtlists.cxx
index a4ec881da6a3..14de8ffb551e 100644
--- a/xmloff/source/text/txtlists.cxx
+++ b/xmloff/source/text/txtlists.cxx
@@ -21,6 +21,7 @@
#include <txtlists.hxx>
#include <comphelper/random.hxx>
+#include <o3tl/safeint.hxx>
#include <tools/datetime.hxx>
#include <sal/log.hxx>
@@ -369,7 +370,7 @@ XMLTextListsHelper::EnsureNumberedParagraph(
if (static_cast<sal_uInt16>(io_rLevel) + 1U > rNPList.size()) {
// new level: need to enlarge
for (size_t i = rNPList.size();
- i < static_cast<size_t>(io_rLevel); ++i)
+ i < o3tl::make_unsigned(io_rLevel); ++i)
{
NumParaList_t::value_type const rule(rNPList.back());
rNPList.push_back(rule);
@@ -388,7 +389,7 @@ XMLTextListsHelper::EnsureNumberedParagraph(
}
}
// remember the list id
- if (mLastNumberedParagraphs.size() <= static_cast<size_t>(io_rLevel)) {
+ if (mLastNumberedParagraphs.size() <= o3tl::make_unsigned(io_rLevel)) {
mLastNumberedParagraphs.resize(io_rLevel+1);
}
mLastNumberedParagraphs[io_rLevel] = std::make_pair(i_StyleName, i_ListId);
diff --git a/xmlscript/source/xml_helper/xml_element.cxx b/xmlscript/source/xml_helper/xml_element.cxx
index 5bcb109cd044..2c7c71c58e31 100644
--- a/xmlscript/source/xml_helper/xml_element.cxx
+++ b/xmlscript/source/xml_helper/xml_element.cxx
@@ -18,6 +18,7 @@
*/
#include <xmlscript/xml_helper.hxx>
+#include <o3tl/safeint.hxx>
#include <osl/diagnose.h>
#include <com/sun/star/xml/sax/XDocumentHandler.hpp>
@@ -70,13 +71,13 @@ sal_Int16 XMLElement::getLength()
OUString XMLElement::getNameByIndex( sal_Int16 nPos )
{
- OSL_ASSERT( static_cast<size_t>(nPos) < _attrNames.size() );
+ OSL_ASSERT( nPos >= 0 && o3tl::make_unsigned(nPos) < _attrNames.size() );
return _attrNames[ nPos ];
}
OUString XMLElement::getTypeByIndex( sal_Int16 nPos )
{
- OSL_ASSERT( static_cast<size_t>(nPos) < _attrNames.size() );
+ OSL_ASSERT( nPos >= 0 && o3tl::make_unsigned(nPos) < _attrNames.size() );
// xxx todo
return OUString();
}
@@ -89,7 +90,7 @@ OUString XMLElement::getTypeByName( OUString const & /*rName*/ )
OUString XMLElement::getValueByIndex( sal_Int16 nPos )
{
- OSL_ASSERT( static_cast<size_t>(nPos) < _attrNames.size() );
+ OSL_ASSERT( nPos >= 0 && o3tl::make_unsigned(nPos) < _attrNames.size() );
return _attrValues[ nPos ];
}