New loplugin:unsignedcompare

Desktop / LibreOffice - Stephan Bergmann [redhat.com] - 28 January 2020 06:42 UTC

"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(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

aef7feb3e695 New loplugin:unsignedcompare
.../source/standard/vclxaccessiblelist.cxx | 2 +-
.../source/standard/vclxaccessibletabcontrol.cxx | 9 +-
.../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 +-
.../controller/accessibility/AccessibleBase.cxx | 3 +-
chart2/source/controller/dialogs/DataBrowser.cxx | 5 +-
.../source/controller/dialogs/DataBrowserModel.cxx | 11 +-
.../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 +-
.../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 +-
.../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 +-
.../source/uielement/addonstoolbarmanager.cxx | 3 +-
.../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 +-
.../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 +-
.../ui/Accessibility/AccessibleFilterMenu.cxx | 11 +-
.../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 +-
.../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 +-
.../controller/SlsAnimationFunction.cxx | 6 +-
.../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 +-
.../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 +-
.../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 +-
.../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 +-
.../controls/grid/defaultgridcolumnmodel.cxx | 3 +-
.../source/controls/grid/defaultgriddatamodel.cxx | 19 +-
.../source/controls/grid/sortablegriddatamodel.cxx | 7 +-
toolkit/source/controls/unocontrols.cxx | 14 +-
tools/source/stream/stream.cxx | 11 +-
.../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 +-
.../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(-)

Upstream: cgit.freedesktop.org


  • Share