[Libreoffice-commits] core.git: accessibility/source avmedia/source basic/source binaryurp/source chart2/source comphelper/source compilerplugins/clang configmgr/source connectivity/source cppuhelper/source cui/source dbaccess/source drawinglayer/source editeng/source emfio/source extensions/source filter/source forms/source fpicker/source framework/source hwpfilter/source i18npool/source idlc/source include/oox linguistic/source oox/source opencl/source reportdesign/source sal/osl sal/textenc sc/source sdext/source sd/qa sd/source sfx2/source slideshow/source solenv/CompilerTest_compilerplugins_clang.mk sot/source starmath/source stoc/source svl/source svtools/source svx/source sw/qa sw/source test/source toolkit/source tools/source unotools/source unoxml/source vbahelper/source vcl/inc vcl/qt5 vcl/source vcl/unx vcl/workben writerperfect/qa writerperfect/source xmlhelp/source xmloff/source xmlscript/source

Stephan Bergmann (via logerrit) logerrit at kemper.freedesktop.org
Tue Jan 28 06:43:26 UTC 2020


 accessibility/source/standard/vclxaccessiblelist.cxx              |    2 
 accessibility/source/standard/vclxaccessibletabcontrol.cxx        |    9 
 accessibility/source/standard/vclxaccessibletoolbox.cxx           |    7 
 avmedia/source/gstreamer/gstframegrabber.cxx                      |    4 
 avmedia/source/gstreamer/gstplayer.cxx                            |    4 
 basic/source/runtime/runtime.cxx                                  |    4 
 basic/source/sbx/sbxarray.cxx                                     |    4 
 basic/source/sbx/sbxbyte.cxx                                      |    5 
 basic/source/sbx/sbxint.cxx                                       |    3 
 binaryurp/source/bridgefactory.cxx                                |    3 
 chart2/source/controller/accessibility/AccessibleBase.cxx         |    3 
 chart2/source/controller/dialogs/DataBrowser.cxx                  |    5 
 chart2/source/controller/dialogs/DataBrowserModel.cxx             |   11 
 chart2/source/controller/drawinglayer/ViewElementListProvider.cxx |    4 
 chart2/source/controller/main/ElementSelector.cxx                 |    3 
 chart2/source/model/main/BaseCoordinateSystem.cxx                 |    3 
 chart2/source/tools/ExplicitCategoriesProvider.cxx                |    3 
 chart2/source/view/axes/Tickmarks_Equidistant.hxx                 |    4 
 comphelper/source/eventattachermgr/eventattachermgr.cxx           |    9 
 comphelper/source/streaming/oslfile2streamwrap.cxx                |    3 
 compilerplugins/clang/test/unsignedcompare.cxx                    |   16 
 compilerplugins/clang/unsignedcompare.cxx                         |  231 ++++++++++
 configmgr/source/dconf.cxx                                        |   22 
 configmgr/source/writemodfile.cxx                                 |    3 
 connectivity/source/commontools/dbtools.cxx                       |    3 
 connectivity/source/commontools/parameters.cxx                    |    5 
 connectivity/source/drivers/dbase/DTable.cxx                      |   17 
 connectivity/source/drivers/dbase/dindexnode.cxx                  |    3 
 connectivity/source/drivers/file/FStatement.cxx                   |    5 
 connectivity/source/drivers/flat/ETable.cxx                       |    9 
 connectivity/source/drivers/mork/MResultSet.cxx                   |    3 
 connectivity/source/drivers/odbc/OResultSet.cxx                   |    3 
 connectivity/source/drivers/odbc/OTools.cxx                       |    5 
 cppuhelper/source/servicemanager.cxx                              |    7 
 cui/source/options/optgenrl.cxx                                   |    5 
 cui/source/tabpages/numfmt.cxx                                    |    5 
 dbaccess/source/core/api/RowSet.cxx                               |    9 
 dbaccess/source/core/api/RowSetBase.cxx                           |    3 
 dbaccess/source/core/api/RowSetCache.cxx                          |    3 
 dbaccess/source/ui/browser/formadapter.cxx                        |    9 
 dbaccess/source/ui/control/RelationControl.cxx                    |    5 
 dbaccess/source/ui/dlg/generalpage.cxx                            |    5 
 dbaccess/source/ui/dlg/paramdialog.cxx                            |    7 
 dbaccess/source/ui/misc/WCopyTable.cxx                            |    4 
 dbaccess/source/ui/querydesign/JAccess.cxx                        |    3 
 dbaccess/source/ui/querydesign/QueryDesignView.cxx                |    3 
 drawinglayer/source/tools/emfpbrush.cxx                           |   15 
 drawinglayer/source/tools/emfppath.cxx                            |    3 
 drawinglayer/source/tools/emfppen.cxx                             |    5 
 editeng/source/accessibility/AccessibleParaManager.cxx            |   35 -
 editeng/source/editeng/editobj.cxx                                |   12 
 editeng/source/editeng/edtspell.cxx                               |    3 
 editeng/source/editeng/impedit2.cxx                               |    5 
 editeng/source/editeng/impedit3.cxx                               |    3 
 editeng/source/editeng/impedit4.cxx                               |    3 
 editeng/source/items/textitem.cxx                                 |    3 
 editeng/source/outliner/outliner.cxx                              |    3 
 editeng/source/outliner/outlobj.cxx                               |    5 
 editeng/source/outliner/paralist.cxx                              |   10 
 editeng/source/outliner/paralist.hxx                              |    3 
 editeng/source/uno/unotext2.cxx                                   |    3 
 emfio/source/reader/mtftools.cxx                                  |    6 
 emfio/source/reader/wmfreader.cxx                                 |    3 
 extensions/source/dbpilots/groupboxwiz.cxx                        |    5 
 extensions/source/scanner/sane.cxx                                |    4 
 extensions/source/scanner/scanunx.cxx                             |    9 
 filter/source/graphicfilter/icgm/cgm.cxx                          |    8 
 filter/source/graphicfilter/icgm/class1.cxx                       |    2 
 filter/source/graphicfilter/icgm/class7.cxx                       |    5 
 filter/source/graphicfilter/idxf/dxfentrd.cxx                     |    9 
 filter/source/graphicfilter/ieps/ieps.cxx                         |    6 
 filter/source/msfilter/msdffimp.cxx                               |    7 
 filter/source/msfilter/mstoolbar.cxx                              |    3 
 filter/source/msfilter/svdfppt.cxx                                |    4 
 forms/source/component/Filter.cxx                                 |    3 
 forms/source/component/GroupManager.cxx                           |    3 
 forms/source/component/ListBox.cxx                                |    5 
 fpicker/source/office/fileview.cxx                                |    3 
 framework/source/fwe/classes/addonsoptions.cxx                    |    7 
 framework/source/services/autorecovery.cxx                        |    3 
 framework/source/uielement/addonstoolbarmanager.cxx               |    3 
 framework/source/uifactory/addonstoolbarfactory.cxx               |    5 
 hwpfilter/source/hwpfile.cxx                                      |   21 
 hwpfilter/source/hwpreader.cxx                                    |    3 
 i18npool/source/breakiterator/breakiterator_th.cxx                |    7 
 idlc/source/idlccompile.cxx                                       |    3 
 include/oox/helper/helper.hxx                                     |   17 
 linguistic/source/gciterator.cxx                                  |    5 
 oox/source/core/contexthandler2.cxx                               |    3 
 oox/source/export/drawingml.cxx                                   |    3 
 opencl/source/opencl_device.cxx                                   |    3 
 reportdesign/source/filter/xml/xmlTable.cxx                       |    7 
 reportdesign/source/ui/dlg/CondFormat.cxx                         |    4 
 reportdesign/source/ui/inspection/GeometryHandler.cxx             |    3 
 reportdesign/source/ui/misc/FunctionHelper.cxx                    |    7 
 sal/osl/unx/file.cxx                                              |    3 
 sal/osl/unx/file_url.cxx                                          |    3 
 sal/osl/unx/pipe.cxx                                              |    3 
 sal/osl/unx/security.cxx                                          |   11 
 sal/textenc/converter.cxx                                         |    3 
 sc/source/core/data/column.cxx                                    |   11 
 sc/source/core/data/column2.cxx                                   |   10 
 sc/source/core/data/column4.cxx                                   |    9 
 sc/source/core/data/columnspanset.cxx                             |    6 
 sc/source/core/data/dociter.cxx                                   |    3 
 sc/source/core/data/documen2.cxx                                  |    3 
 sc/source/core/data/document.cxx                                  |   11 
 sc/source/core/data/documentimport.cxx                            |    5 
 sc/source/core/data/dpcache.cxx                                   |    5 
 sc/source/core/data/dpfilteredcache.cxx                           |    4 
 sc/source/core/data/dpoutput.cxx                                  |   19 
 sc/source/core/data/dptabres.cxx                                  |   11 
 sc/source/core/data/dptabsrc.cxx                                  |    5 
 sc/source/core/data/table1.cxx                                    |    3 
 sc/source/core/data/table2.cxx                                    |    5 
 sc/source/core/tool/compiler.cxx                                  |    7 
 sc/source/core/tool/dbdata.cxx                                    |    3 
 sc/source/core/tool/grouparealistener.cxx                         |    3 
 sc/source/core/tool/interpr1.cxx                                  |   13 
 sc/source/core/tool/interpr4.cxx                                  |    5 
 sc/source/core/tool/token.cxx                                     |    3 
 sc/source/filter/excel/excdoc.cxx                                 |    5 
 sc/source/filter/excel/excform8.cxx                               |    4 
 sc/source/filter/excel/impop.cxx                                  |    3 
 sc/source/filter/excel/xeformula.cxx                              |    7 
 sc/source/filter/excel/xepivotxml.cxx                             |    3 
 sc/source/filter/excel/xestring.cxx                               |    5 
 sc/source/filter/excel/xestyle.cxx                                |    3 
 sc/source/filter/excel/xiview.cxx                                 |    6 
 sc/source/filter/excel/xladdress.cxx                              |    5 
 sc/source/filter/oox/externallinkbuffer.cxx                       |    3 
 sc/source/filter/oox/formulabuffer.cxx                            |   13 
 sc/source/filter/oox/pivotcachebuffer.cxx                         |    3 
 sc/source/filter/xml/XMLStylesExportHelper.cxx                    |   45 -
 sc/source/ui/Accessibility/AccessibleDocument.cxx                 |    6 
 sc/source/ui/Accessibility/AccessibleFilterMenu.cxx               |   11 
 sc/source/ui/Accessibility/AccessibleSpreadsheet.cxx              |    5 
 sc/source/ui/condformat/condformathelper.cxx                      |    5 
 sc/source/ui/dbgui/consdlg.cxx                                    |    3 
 sc/source/ui/docshell/docfunc.cxx                                 |    3 
 sc/source/ui/docshell/externalrefmgr.cxx                          |   11 
 sc/source/ui/unoobj/PivotTableDataProvider.cxx                    |    7 
 sc/source/ui/unoobj/PivotTableDataSequence.cxx                    |    4 
 sc/source/ui/unoobj/cellsuno.cxx                                  |    5 
 sc/source/ui/unoobj/chart2uno.cxx                                 |    5 
 sc/source/ui/unoobj/condformatuno.cxx                             |    7 
 sc/source/ui/unoobj/docuno.cxx                                    |    5 
 sc/source/ui/vba/vbawindow.cxx                                    |    3 
 sc/source/ui/vba/vbawindows.cxx                                   |    3 
 sc/source/ui/view/viewdata.cxx                                    |    8 
 sd/qa/unit/export-tests.cxx                                       |    2 
 sd/qa/unit/sdmodeltestbase.hxx                                    |    4 
 sd/source/core/CustomAnimationEffect.cxx                          |    3 
 sd/source/core/sdpage.cxx                                         |    3 
 sd/source/filter/html/htmlex.cxx                                  |    3 
 sd/source/filter/pdf/sdpdffilter.cxx                              |    5 
 sd/source/ui/accessibility/AccessibleSlideSorterView.cxx          |    5 
 sd/source/ui/animations/SlideTransitionPane.cxx                   |    3 
 sd/source/ui/dlg/tpaction.cxx                                     |    6 
 sd/source/ui/sidebar/MasterPageContainer.cxx                      |    7 
 sd/source/ui/sidebar/MasterPagesSelector.cxx                      |    3 
 sd/source/ui/slidesorter/controller/SlsAnimationFunction.cxx      |    6 
 sd/source/ui/slidesorter/view/SlsInsertionIndicatorOverlay.cxx    |    3 
 sd/source/ui/slidesorter/view/SlsLayeredDevice.cxx                |   11 
 sdext/source/pdfimport/pdfparse/pdfparse.cxx                      |    5 
 sdext/source/presenter/PresenterAccessibility.cxx                 |    3 
 sdext/source/presenter/PresenterTextView.cxx                      |    5 
 sfx2/source/appl/sfxhelp.cxx                                      |    5 
 sfx2/source/bastyp/mieclip.cxx                                    |    5 
 sfx2/source/dialog/dockwin.cxx                                    |    3 
 sfx2/source/sidebar/TabBar.cxx                                    |    5 
 slideshow/source/engine/opengl/TransitionImpl.hxx                 |    3 
 slideshow/source/engine/shapes/drawshapesubsetting.cxx            |    8 
 solenv/CompilerTest_compilerplugins_clang.mk                      |    1 
 sot/source/sdstor/stgelem.cxx                                     |    4 
 starmath/source/AccessibleSmElementsControl.cxx                   |    5 
 stoc/source/typeconv/convert.cxx                                  |   13 
 svl/source/items/macitem.cxx                                      |    3 
 svl/source/misc/strmadpt.cxx                                      |    4 
 svl/source/numbers/zforscan.cxx                                   |    3 
 svtools/source/brwbox/brwbox1.cxx                                 |    3 
 svtools/source/brwbox/brwbox2.cxx                                 |    2 
 svtools/source/control/valueset.cxx                               |   13 
 svtools/source/dialogs/ServerDetailsControls.cxx                  |    3 
 svtools/source/uno/unocontroltablemodel.cxx                       |    6 
 svx/source/accessibility/ChildrenManagerImpl.cxx                  |    4 
 svx/source/accessibility/GraphCtlAccessibleContext.cxx            |    3 
 svx/source/dialog/frmsel.cxx                                      |    5 
 svx/source/form/filtnav.cxx                                       |    7 
 svx/source/form/fmshimp.cxx                                       |    4 
 svx/source/form/fmsrcimp.cxx                                      |    8 
 svx/source/form/formcontroller.cxx                                |    7 
 svx/source/form/navigatortreemodel.cxx                            |    3 
 svx/source/items/numfmtsh.cxx                                     |   12 
 svx/source/svdraw/svdotextpathdecomposition.cxx                   |    4 
 svx/source/svdraw/svdpage.cxx                                     |    3 
 svx/source/tbxctrls/tbcontrl.cxx                                  |    3 
 svx/source/unodraw/unopage.cxx                                    |    3 
 svx/source/unodraw/unoshap2.cxx                                   |    3 
 svx/source/unodraw/unoshap3.cxx                                   |    3 
 svx/source/xoutdev/xtable.cxx                                     |    3 
 sw/qa/extras/globalfilter/globalfilter.cxx                        |    5 
 sw/source/core/access/accselectionhelper.cxx                      |    5 
 sw/source/core/access/acctable.cxx                                |    5 
 sw/source/core/crsr/findtxt.cxx                                   |    3 
 sw/source/core/doc/DocumentContentOperationsManager.cxx           |    3 
 sw/source/core/doc/doccomp.cxx                                    |    7 
 sw/source/core/doc/docnum.cxx                                     |    5 
 sw/source/core/edit/edglss.cxx                                    |    5 
 sw/source/core/fields/cellfml.cxx                                 |    5 
 sw/source/core/text/itradj.cxx                                    |    6 
 sw/source/core/text/redlnitr.cxx                                  |    3 
 sw/source/core/tox/ToxWhitespaceStripper.cxx                      |    3 
 sw/source/core/txtnode/txtedt.cxx                                 |    3 
 sw/source/core/unocore/unocoll.cxx                                |    5 
 sw/source/core/unocore/unofield.cxx                               |    3 
 sw/source/core/unocore/unoflatpara.cxx                            |    5 
 sw/source/core/unocore/unoobj.cxx                                 |    3 
 sw/source/core/unocore/unoobj2.cxx                                |    3 
 sw/source/core/unocore/unoredlines.cxx                            |    3 
 sw/source/core/unocore/unostyle.cxx                               |    5 
 sw/source/core/unocore/unotbl.cxx                                 |    7 
 sw/source/core/unocore/unotextmarkup.cxx                          |    5 
 sw/source/filter/basflt/fltshell.cxx                              |    3 
 sw/source/filter/html/htmlplug.cxx                                |    3 
 sw/source/filter/ww8/wrtww8.cxx                                   |    5 
 sw/source/filter/ww8/ww8atr.cxx                                   |    5 
 sw/source/filter/ww8/ww8par.cxx                                   |    9 
 sw/source/filter/ww8/ww8par2.cxx                                  |   11 
 sw/source/filter/ww8/ww8par6.cxx                                  |    5 
 sw/source/filter/ww8/ww8scan.cxx                                  |    8 
 sw/source/filter/ww8/ww8toolbar.cxx                               |    9 
 sw/source/ui/dbui/mmaddressblockpage.cxx                          |    3 
 sw/source/ui/fldui/fldref.cxx                                     |    3 
 sw/source/ui/frmdlg/frmpage.cxx                                   |    3 
 sw/source/ui/index/cnttab.cxx                                     |    5 
 sw/source/uibase/dbui/mailmergehelper.cxx                         |    5 
 sw/source/uibase/uno/unoatxt.cxx                                  |    7 
 test/source/sheet/xdatapilotdescriptor.cxx                        |    3 
 toolkit/source/awt/animatedimagespeer.cxx                         |    3 
 toolkit/source/controls/animatedimages.cxx                        |    4 
 toolkit/source/controls/grid/defaultgridcolumnmodel.cxx           |    3 
 toolkit/source/controls/grid/defaultgriddatamodel.cxx             |   19 
 toolkit/source/controls/grid/sortablegriddatamodel.cxx            |    7 
 toolkit/source/controls/unocontrols.cxx                           |   14 
 tools/source/stream/stream.cxx                                    |   11 
 unotools/source/accessibility/accessiblerelationsethelper.cxx     |    3 
 unotools/source/streaming/streamhelper.cxx                        |    3 
 unotools/source/streaming/streamwrap.cxx                          |    3 
 unotools/source/ucbhelper/xtempfile.cxx                           |    3 
 unoxml/source/dom/elementlist.cxx                                 |    3 
 vbahelper/source/vbahelper/vbadocumentsbase.cxx                   |    3 
 vcl/inc/listbox.hxx                                               |    5 
 vcl/qt5/Qt5Menu.cxx                                               |    9 
 vcl/source/app/salvtables.cxx                                     |   17 
 vcl/source/control/edit.cxx                                       |   10 
 vcl/source/control/imivctl.hxx                                    |    7 
 vcl/source/control/imivctl2.cxx                                   |    2 
 vcl/source/control/imp_listbox.cxx                                |    5 
 vcl/source/filter/FilterConfigCache.cxx                           |    5 
 vcl/source/fontsubset/cff.cxx                                     |    3 
 vcl/source/gdi/dibtools.cxx                                       |    7 
 vcl/source/gdi/pdfextoutdevdata.cxx                               |    7 
 vcl/source/gdi/pdfwriter_impl.hxx                                 |    3 
 vcl/source/gdi/svmconverter.cxx                                   |    6 
 vcl/source/treelist/svimpbox.cxx                                  |    7 
 vcl/source/treelist/svtabbx.cxx                                   |    3 
 vcl/source/window/syswin.cxx                                      |   10 
 vcl/source/window/winproc.cxx                                     |    5 
 vcl/unx/generic/app/i18n_cb.cxx                                   |    3 
 vcl/unx/generic/glyphs/freetype_glyphcache.cxx                    |    4 
 vcl/unx/generic/printer/ppdparser.cxx                             |    7 
 vcl/unx/gtk3/gtk3gtkdata.cxx                                      |    3 
 vcl/workben/vcldemo.cxx                                           |    4 
 writerperfect/qa/unit/EPUBExportTest.cxx                          |    3 
 writerperfect/source/common/WPXSvInputStream.cxx                  |    6 
 xmlhelp/source/treeview/tvread.cxx                                |    9 
 xmloff/source/chart/SchXMLTableContext.cxx                        |    3 
 xmloff/source/core/attrlist.cxx                                   |   12 
 xmloff/source/core/unointerfacetouniqueidentifiermapper.cxx       |    5 
 xmloff/source/text/txtlists.cxx                                   |    5 
 xmlscript/source/xml_helper/xml_element.cxx                       |    7 
 282 files changed, 1202 insertions(+), 633 deletions(-)

New commits:
commit aef7feb3e695ecf6d411f0777196dcc4281e201a
Author:     Stephan Bergmann <sbergman at redhat.com>
AuthorDate: Mon Jan 27 09:30:39 2020 +0100
Commit:     Stephan Bergmann <sbergman at redhat.com>
CommitDate: Tue Jan 28 07:42:15 2020 +0100

    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 at redhat.com>

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 at +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();
             }

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list