Make SfxItemSet ranges correct by construction

Desktop / LibreOffice - Stephan Bergmann [redhat.com] - 16 June 2017 11:28 EDT

This is a follow-up to 45a7f5b62d0b1b21763c1c94255ef2309ea4280b "Keep WID ranges sorted, and join adjacent ones". While SfxItemSet::MergeRange relies on the m_pWhichRanges being sorted (and, under DBG_UTIL, asserts if they are not), the
various SfxItemSet constructors curiously only check (via assert or DBG_ASSERT) that each individual range has an upper bound not smaller than its lower bound. Arguably, all SfxItemSet instances should fulfill the stronger guarantees required and checked by MergeRange.

And in many cases the ranges are statically known, so that the checking can happen at compile time. Therefore, replace the two SfxItemSet ctors taking explicit ranges with two other ctors that actually do proper checking. The (templated) overload taking an svl::Items struct should be used in all cases where the range values are statically known at compile time, while the overload taking a std::initializer_list is for the remaining cases (that can only do runtime checking via assert). Most of those latter cases are simple cases with a single range covering a single item, but a few are more complex.

(At least some of the uses of the existing SfxItemSet overload taking a

const sal_uInt16* pWhichPairTable

can probably also be strengthened, but that is left for another day.)

This commit is the first in a series of two. Apart from the manual changes to compilerplugins/clang/store/sfxitemsetrewrite.cxx, include/svl/itemset.hxx, and svl/source/items/itemset.cxx, it only consists of automatic rewriting of the relevant SfxItemSet ctor calls (plus a few required manual fixes, see next). But it does not yet check that the individual ranges are properly sorted (see the TODO in svl::detail::validGap). That check will be enabled, and the ensuing manual fixes will be made in a follow-up commit, to reduce the likelyhood of accidents.

There were three cases of necessary manual intervention:

- sw/source/core/unocore/unostyle.cxx uses eAtr of enum type RES_FRMATR in braced-init-list syntax now, so needs explicit narrowing conversion to sal_uInt16.

- In sw/source/uibase/uiview/formatclipboard.cxx, the trailiing comma in the definition of macro FORMAT_PAINTBRUSH_FRAME_IDS needed to be removed manually.

- In svx/source/svdraw/svdoashp.cxx, svx/source/svdraw/svdotext.cxx, sw/source/uibase/app/docstyle.cxx, sw/source/uibase/shells/frmsh.cxx, sw/source/uibase/shells/grfsh.cxx, and sw/source/uibase/shells/textsh1.cxx, some comments had to be put back (see "TODO: the replaced range can contain relevant comments" in compilerplugins/clang/store/sfxitemsetrewrite.cxx).

A few uses of the variadic form erroneously used nullptr instead of 0 for termination. But this should have been harmless even if promoted std::nullptr_t is larger than promoted sal_uInt16, assuming that the part of the nullptr value that was interpreted as sal_uInt16/promoted int was all-zero bits. Similarly, some uses made the harmless error of using 0L instead of 0.

Change-Id: I2afea97282803cb311b9321a99bb627520ef5e35 Reviewed-on: https://gerrit.libreoffice.org/38861

13bb5a4 Make SfxItemSet ranges correct by construction
basctl/source/basicide/basdoc.cxx | 2 +-
.../controller/drawinglayer/DrawViewWrapper.cxx | 5 +-
.../source/controller/main/DrawCommandDispatch.cxx | 6 +-
chart2/source/controller/main/ShapeController.cxx | 5 +-
compilerplugins/clang/store/sfxitemsetrewrite.cxx | 262 +++++++++++++++++++++
cui/source/dialogs/cuihyperdlg.cxx | 8 +-
cui/source/dialogs/hltpbase.cxx | 4 +-
cui/source/factory/dlgfact.cxx | 2 +-
cui/source/options/treeopt.cxx | 29 +--
cui/source/tabpages/bbdlg.cxx | 5 +-
cui/source/tabpages/page.cxx | 10 +-
desktop/source/app/app.cxx | 2 +-
editeng/source/editeng/editdoc.cxx | 4 +-
editeng/source/editeng/editobj.cxx | 4 +-
editeng/source/editeng/impedit2.cxx | 2 +-
editeng/source/editeng/impedit4.cxx | 6 +-
editeng/source/items/textitem.cxx | 2 +-
editeng/source/uno/unofdesc.cxx | 4 +-
editeng/source/uno/unoipset.cxx | 2 +-
editeng/source/uno/unotext.cxx | 2 +-
.../source/propctrlr/formcomponenthandler.cxx | 5 +-
include/svl/itemset.hxx | 67 +++++-
reportdesign/source/ui/misc/UITools.cxx | 2 +-
reportdesign/source/ui/report/ReportSection.cxx | 6 +-
sc/qa/unit/ucalc_formula.cxx | 2 +-
sc/source/core/data/docpool.cxx | 7 +-
sc/source/core/data/documen8.cxx | 5 +-
sc/source/core/data/patattr.cxx | 4 +-
sc/source/core/data/stlsheet.cxx | 7 +-
sc/source/core/data/table2.cxx | 2 +-
sc/source/core/tool/detfunc.cxx | 12 +-
sc/source/filter/excel/xehelper.cxx | 4 +-
sc/source/filter/excel/xlroot.cxx | 2 +-
sc/source/filter/starcalc/scflt.cxx | 5 +-
sc/source/ui/app/scmod.cxx | 7 +-
sc/source/ui/docshell/docsh3.cxx | 5 +-
sc/source/ui/drawfunc/drawsh.cxx | 4 +-
sc/source/ui/drawfunc/drawsh5.cxx | 2 +-
sc/source/ui/drawfunc/drtxtob.cxx | 8 +-
sc/source/ui/drawfunc/drtxtob1.cxx | 5 +-
sc/source/ui/drawfunc/drtxtob2.cxx | 9 +-
sc/source/ui/drawfunc/fuconcustomshape.cxx | 6 +-
sc/source/ui/drawfunc/futext.cxx | 4 +-
sc/source/ui/pagedlg/tphf.cxx | 4 +-
sc/source/ui/unoobj/confuno.cxx | 5 +-
sc/source/ui/view/cellsh1.cxx | 2 +-
sc/source/ui/view/cellsh2.cxx | 2 +-
sc/source/ui/view/cellsh3.cxx | 8 +-
sc/source/ui/view/drawview.cxx | 2 +-
sc/source/ui/view/formatsh.cxx | 12 +-
sc/source/ui/view/gridwin2.cxx | 2 +-
sc/source/ui/view/gridwin3.cxx | 2 +-
sc/source/ui/view/pivotsh.cxx | 2 +-
sc/source/ui/view/prevwsh.cxx | 2 +-
sc/source/ui/view/tabvwsh3.cxx | 2 +-
sc/source/ui/view/tabvwshc.cxx | 12 +-
sc/source/ui/view/viewfun2.cxx | 8 +-
sc/source/ui/view/viewfunc.cxx | 2 +-
sd/qa/unit/dialogs-test.cxx | 10 +-
sd/source/core/sdpage.cxx | 4 +-
sd/source/core/sdpage2.cxx | 2 +-
sd/source/core/stlsheet.cxx | 6 +-
sd/source/ui/app/sdmod2.cxx | 10 +-
sd/source/ui/dlg/dlgfield.cxx | 2 +-
sd/source/ui/dlg/prltempl.cxx | 2 +-
sd/source/ui/docshell/docshel4.cxx | 5 +-
sd/source/ui/func/fubullet.cxx | 2 +-
sd/source/ui/func/fuconcs.cxx | 6 +-
sd/source/ui/func/fucopy.cxx | 6 +-
sd/source/ui/func/fuexpand.cxx | 2 +-
sd/source/ui/func/fumorph.cxx | 2 +-
sd/source/ui/func/fuoaprms.cxx | 2 +-
sd/source/ui/func/fuolbull.cxx | 6 +-
sd/source/ui/func/fupage.cxx | 23 +-
sd/source/ui/func/fuparagr.cxx | 5 +-
sd/source/ui/func/fuprlout.cxx | 2 +-
sd/source/ui/func/fuprobjs.cxx | 2 +-
sd/source/ui/func/fuscale.cxx | 2 +-
sd/source/ui/func/fusldlg.cxx | 2 +-
sd/source/ui/func/fusnapln.cxx | 2 +-
sd/source/ui/func/fusumry.cxx | 2 +-
sd/source/ui/func/futext.cxx | 4 +-
sd/source/ui/unoidl/UnoDocumentSettings.cxx | 5 +-
sd/source/ui/unoidl/unopage.cxx | 4 +-
sd/source/ui/unoidl/unopback.cxx | 10 +-
sd/source/ui/view/drtxtob.cxx | 2 +-
sd/source/ui/view/drtxtob1.cxx | 6 +-
sd/source/ui/view/drviews2.cxx | 14 +-
sd/source/ui/view/drviews3.cxx | 18 +-
sd/source/ui/view/drviews4.cxx | 5 +-
sd/source/ui/view/drviews7.cxx | 4 +-
sd/source/ui/view/drviewsf.cxx | 2 +-
sd/source/ui/view/drviewsi.cxx | 5 +-
sd/source/ui/view/outlnvsh.cxx | 4 +-
sd/source/ui/view/sdview.cxx | 4 +-
sd/source/ui/view/sdview3.cxx | 4 +-
sd/source/ui/view/sdview4.cxx | 2 +-
sfx2/source/appl/appserv.cxx | 4 +-
sfx2/source/control/bindings.cxx | 2 +-
sfx2/source/control/shell.cxx | 4 +-
sfx2/source/doc/objserv.cxx | 5 +-
starmath/qa/cppunit/test_starmath.cxx | 8 +-
starmath/source/document.cxx | 5 +-
starmath/source/smmod.cxx | 5 +-
starmath/source/view.cxx | 2 +-
svl/source/items/itemset.cxx | 140 ++++-------
svx/source/dialog/databaseregistrationui.cxx | 2 +-
svx/source/dialog/dlgctl3d.cxx | 7 +-
svx/source/dialog/hdft.cxx | 28 +--
svx/source/dialog/imapwnd.cxx | 2 +-
svx/source/engine3d/float3d.cxx | 7 +-
svx/source/engine3d/view3d1.cxx | 9 +-
svx/source/sdr/properties/attributeproperties.cxx | 7 +-
svx/source/sdr/properties/captionproperties.cxx | 7 +-
svx/source/sdr/properties/circleproperties.cxx | 7 +-
svx/source/sdr/properties/connectorproperties.cxx | 7 +-
.../sdr/properties/customshapeproperties.cxx | 7 +-
svx/source/sdr/properties/defaultproperties.cxx | 6 +-
.../sdr/properties/e3dcompoundproperties.cxx | 4 +-
svx/source/sdr/properties/e3dproperties.cxx | 7 +-
svx/source/sdr/properties/e3dsceneproperties.cxx | 2 +-
svx/source/sdr/properties/graphicproperties.cxx | 7 +-
svx/source/sdr/properties/measureproperties.cxx | 7 +-
svx/source/sdr/properties/textproperties.cxx | 9 +-
svx/source/svdraw/svddrgmt.cxx | 2 +-
svx/source/svdraw/svdedtv1.cxx | 5 +-
svx/source/svdraw/svdedtv2.cxx | 5 +-
svx/source/svdraw/svdfmtf.cxx | 10 +-
svx/source/svdraw/svdibrow.cxx | 2 +-
svx/source/svdraw/svdoashp.cxx | 10 +-
svx/source/svdraw/svdotext.cxx | 10 +-
svx/source/svdraw/svdotxed.cxx | 2 +-
svx/source/svdraw/svdpage.cxx | 2 +-
svx/source/table/cell.cxx | 16 +-
svx/source/table/svdotable.cxx | 7 +-
svx/source/tbxctrls/grafctrl.cxx | 8 +-
svx/source/unodraw/UnoNameItemTable.cxx | 2 +-
svx/source/unodraw/unomtabl.cxx | 2 +-
svx/source/unodraw/unoshape.cxx | 10 +-
svx/source/xoutdev/xattr.cxx | 8 +-
svx/source/xoutdev/xexch.cxx | 2 +-
svx/source/xoutdev/xpool.cxx | 4 +-
sw/qa/core/uwriter.cxx | 2 +-
sw/qa/extras/tiledrendering/tiledrendering.cxx | 14 +-
sw/qa/extras/uiwriter/uiwriter.cxx | 16 +-
sw/qa/extras/ww8export/ww8export.cxx | 2 +-
sw/source/core/access/accpara.cxx | 30 +--
sw/source/core/attr/format.cxx | 2 +-
sw/source/core/attr/swatrset.cxx | 2 +-
sw/source/core/crsr/crstrvl.cxx | 9 +-
sw/source/core/crsr/findattr.cxx | 4 +-
.../core/doc/DocumentContentOperationsManager.cxx | 25 +-
sw/source/core/doc/DocumentDeviceManager.cxx | 10 +-
sw/source/core/doc/DocumentFieldsManager.cxx | 2 +-
sw/source/core/doc/docfly.cxx | 4 +-
sw/source/core/doc/docfmt.cxx | 12 +-
sw/source/core/doc/docnew.cxx | 2 +-
sw/source/core/doc/docsort.cxx | 4 +-
sw/source/core/doc/tblcpy.cxx | 4 +-
sw/source/core/doc/tblrwcl.cxx | 2 +-
sw/source/core/docnode/ndtbl.cxx | 11 +-
sw/source/core/docnode/node.cxx | 4 +-
sw/source/core/draw/dcontact.cxx | 4 +-
sw/source/core/draw/dflyobj.cxx | 2 +-
sw/source/core/edit/acorrect.cxx | 2 +-
sw/source/core/edit/autofmt.cxx | 10 +-
sw/source/core/edit/edfmt.cxx | 4 +-
sw/source/core/edit/edlingu.cxx | 4 +-
sw/source/core/fields/cellfml.cxx | 2 +-
sw/source/core/frmedt/fecopy.cxx | 4 +-
sw/source/core/frmedt/fefly1.cxx | 2 +-
sw/source/core/frmedt/feshview.cxx | 12 +-
sw/source/core/frmedt/fews.cxx | 2 +-
sw/source/core/layout/fly.cxx | 2 +-
sw/source/core/text/redlnitr.cxx | 2 +-
sw/source/core/txtnode/ndtxt.cxx | 17 +-
sw/source/core/txtnode/thints.cxx | 4 +-
sw/source/core/undo/unattr.cxx | 2 +-
sw/source/core/undo/untbl.cxx | 24 +-
sw/source/core/unocore/SwXTextDefaults.cxx | 2 +-
sw/source/core/unocore/unodraw.cxx | 8 +-
sw/source/core/unocore/unoframe.cxx | 16 +-
sw/source/core/unocore/unoobj.cxx | 16 +-
sw/source/core/unocore/unoport.cxx | 5 +-
sw/source/core/unocore/unosect.cxx | 9 +-
sw/source/core/unocore/unostyle.cxx | 15 +-
sw/source/core/unocore/unotbl.cxx | 43 ++--
sw/source/filter/ascii/parasc.cxx | 5 +-
sw/source/filter/basflt/fltshell.cxx | 2 +-
sw/source/filter/html/SwAppletImpl.cxx | 2 +-
sw/source/filter/html/css1atr.cxx | 17 +-
sw/source/filter/html/htmlatr.cxx | 6 +-
sw/source/filter/html/htmlctxt.cxx | 4 +-
sw/source/filter/html/htmldrawreader.cxx | 2 +-
sw/source/filter/html/htmlfldw.cxx | 5 +-
sw/source/filter/html/htmlflywriter.cxx | 4 +-
sw/source/filter/html/htmlforw.cxx | 4 +-
sw/source/filter/html/htmlgrin.cxx | 2 +-
sw/source/filter/html/htmlplug.cxx | 4 +-
sw/source/filter/html/htmlsect.cxx | 6 +-
sw/source/filter/html/htmltab.cxx | 8 +-
sw/source/filter/html/swhtml.cxx | 4 +-
sw/source/filter/ww8/wrtw8nds.cxx | 4 +-
sw/source/filter/ww8/wrtw8num.cxx | 4 +-
sw/source/filter/ww8/wrtw8sty.cxx | 2 +-
sw/source/filter/ww8/wrtww8.cxx | 2 +-
sw/source/filter/ww8/ww8atr.cxx | 9 +-
sw/source/filter/ww8/ww8graf.cxx | 8 +-
sw/source/filter/ww8/ww8graf2.cxx | 8 +-
sw/source/filter/ww8/ww8par.cxx | 2 +-
sw/source/filter/ww8/ww8par2.cxx | 4 +-
sw/source/filter/ww8/ww8par3.cxx | 6 +-
sw/source/filter/ww8/ww8par4.cxx | 4 +-
sw/source/filter/ww8/ww8par5.cxx | 8 +-
sw/source/filter/ww8/ww8par6.cxx | 10 +-
sw/source/filter/xml/xmlfmt.cxx | 2 +-
sw/source/filter/xml/xmltexti.cxx | 20 +-
sw/source/ui/chrdlg/drpcps.cxx | 2 +-
sw/source/ui/chrdlg/pardlg.cxx | 4 +-
sw/source/ui/config/optpage.cxx | 5 +-
sw/source/ui/dbui/dbinsdlg.cxx | 4 +-
sw/source/ui/dbui/mmlayoutpage.cxx | 10 +-
sw/source/ui/dialog/ascfldlg.cxx | 5 +-
sw/source/ui/dialog/macassgn.cxx | 2 +-
sw/source/ui/dialog/uiregionsw.cxx | 5 +-
sw/source/ui/fldui/fldedt.cxx | 5 +-
sw/source/ui/fldui/fldtdlg.cxx | 2 +-
sw/source/ui/frmdlg/column.cxx | 7 +-
sw/source/ui/frmdlg/frmdlg.cxx | 4 +-
sw/source/ui/index/swuiidxmrk.cxx | 2 +-
sw/source/ui/misc/docfnote.cxx | 2 +-
sw/source/ui/misc/glossary.cxx | 2 +-
sw/source/ui/misc/insfnote.cxx | 6 +-
sw/source/ui/misc/titlepage.cxx | 2 +-
sw/source/uibase/app/appenv.cxx | 4 +-
sw/source/uibase/app/applab.cxx | 10 +-
sw/source/uibase/app/appopt.cxx | 8 +-
sw/source/uibase/app/docsh2.cxx | 2 +-
sw/source/uibase/app/docstyle.cxx | 5 +-
sw/source/uibase/dialog/regionsw.cxx | 10 +-
sw/source/uibase/dochdl/swdtflvr.cxx | 20 +-
sw/source/uibase/docvw/HeaderFooterWin.cxx | 4 +-
sw/source/uibase/docvw/PageBreakWin.cxx | 5 +-
sw/source/uibase/docvw/PostItMgr.cxx | 2 +-
sw/source/uibase/docvw/edtwin.cxx | 8 +-
sw/source/uibase/fldui/fldmgr.cxx | 2 +-
sw/source/uibase/frmdlg/colex.cxx | 6 +-
sw/source/uibase/frmdlg/frmmgr.cxx | 2 +-
sw/source/uibase/lingu/olmenu.cxx | 7 +-
sw/source/uibase/misc/glshell.cxx | 5 +-
sw/source/uibase/ribbar/concustomshape.cxx | 6 +-
sw/source/uibase/ribbar/conrect.cxx | 2 +-
sw/source/uibase/ribbar/drawbase.cxx | 2 +-
sw/source/uibase/ribbar/inputwin.cxx | 2 +-
sw/source/uibase/shells/annotsh.cxx | 17 +-
sw/source/uibase/shells/basesh.cxx | 49 ++--
sw/source/uibase/shells/drawsh.cxx | 2 +-
sw/source/uibase/shells/drwbassh.cxx | 7 +-
sw/source/uibase/shells/drwtxtex.cxx | 16 +-
sw/source/uibase/shells/drwtxtsh.cxx | 5 +-
sw/source/uibase/shells/frmsh.cxx | 27 +--
sw/source/uibase/shells/grfsh.cxx | 26 +-
sw/source/uibase/shells/langhelper.cxx | 2 +-
sw/source/uibase/shells/tabsh.cxx | 43 ++--
sw/source/uibase/shells/textfld.cxx | 2 +-
sw/source/uibase/shells/textidx.cxx | 5 +-
sw/source/uibase/shells/textsh.cxx | 11 +-
sw/source/uibase/shells/textsh1.cxx | 37 ++-
sw/source/uibase/shells/txtattr.cxx | 26 +-
sw/source/uibase/shells/txtnum.cxx | 5 +-
sw/source/uibase/uiview/formatclipboard.cxx | 18 +-
sw/source/uibase/uiview/pview.cxx | 4 +-
sw/source/uibase/uiview/view0.cxx | 2 +-
sw/source/uibase/uiview/view2.cxx | 4 +-
sw/source/uibase/uiview/viewdraw.cxx | 4 +-
sw/source/uibase/uiview/viewprt.cxx | 5 +-
sw/source/uibase/uiview/viewtab.cxx | 46 ++--
sw/source/uibase/uno/unotxdoc.cxx | 15 +-
sw/source/uibase/utlui/glbltree.cxx | 5 +-
sw/source/uibase/utlui/numfmtlb.cxx | 5 +-
sw/source/uibase/utlui/uitool.cxx | 12 +-
sw/source/uibase/wrtsh/delete.cxx | 2 +-
sw/source/uibase/wrtsh/wrtsh1.cxx | 5 +-
283 files changed, 1225 insertions(+), 1132 deletions(-)

Upstream: cgit.freedesktop.org


  • Share