summaryrefslogtreecommitdiff
path: root/svx/source/sdr
diff options
context:
space:
mode:
authorStephan Bergmann <sbergman@redhat.com>2017-06-16 09:58:13 +0200
committerStephan Bergmann <sbergman@redhat.com>2017-06-16 17:28:41 +0200
commit13bb5a4b09f5b2ad19dad1b55f45d0fe2b2fb908 (patch)
treed38ad18688a292ff6ccdfaa7c51080197ec95934 /svx/source/sdr
parentf83d8ae84584c0967e2346566d21d65d6d7a432f (diff)
Make SfxItemSet ranges correct by construction
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<Pair> 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 Reviewed-by: Stephan Bergmann <sbergman@redhat.com> Tested-by: Stephan Bergmann <sbergman@redhat.com>
Diffstat (limited to 'svx/source/sdr')
-rw-r--r--svx/source/sdr/properties/attributeproperties.cxx7
-rw-r--r--svx/source/sdr/properties/captionproperties.cxx7
-rw-r--r--svx/source/sdr/properties/circleproperties.cxx7
-rw-r--r--svx/source/sdr/properties/connectorproperties.cxx7
-rw-r--r--svx/source/sdr/properties/customshapeproperties.cxx7
-rw-r--r--svx/source/sdr/properties/defaultproperties.cxx6
-rw-r--r--svx/source/sdr/properties/e3dcompoundproperties.cxx4
-rw-r--r--svx/source/sdr/properties/e3dproperties.cxx7
-rw-r--r--svx/source/sdr/properties/e3dsceneproperties.cxx2
-rw-r--r--svx/source/sdr/properties/graphicproperties.cxx7
-rw-r--r--svx/source/sdr/properties/measureproperties.cxx7
-rw-r--r--svx/source/sdr/properties/textproperties.cxx9
12 files changed, 25 insertions, 52 deletions
diff --git a/svx/source/sdr/properties/attributeproperties.cxx b/svx/source/sdr/properties/attributeproperties.cxx
index 137cc6bd93c0..de3873a8179f 100644
--- a/svx/source/sdr/properties/attributeproperties.cxx
+++ b/svx/source/sdr/properties/attributeproperties.cxx
@@ -118,12 +118,9 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// ranges from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
- SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
-
- // end
- 0, 0);
+ SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION>{});
}
AttributeProperties::AttributeProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/captionproperties.cxx b/svx/source/sdr/properties/captionproperties.cxx
index be25e2ed6e50..2a32b8dab720 100644
--- a/svx/source/sdr/properties/captionproperties.cxx
+++ b/svx/source/sdr/properties/captionproperties.cxx
@@ -38,7 +38,7 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// range from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
@@ -46,10 +46,7 @@ namespace sdr
SDRATTR_CAPTION_FIRST, SDRATTR_CAPTION_LAST,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
CaptionProperties::CaptionProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/circleproperties.cxx b/svx/source/sdr/properties/circleproperties.cxx
index 4168e28e29e7..4782128d79ff 100644
--- a/svx/source/sdr/properties/circleproperties.cxx
+++ b/svx/source/sdr/properties/circleproperties.cxx
@@ -40,7 +40,7 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// range from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
@@ -48,10 +48,7 @@ namespace sdr
SDRATTR_CIRC_FIRST, SDRATTR_CIRC_LAST,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
CircleProperties::CircleProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/connectorproperties.cxx b/svx/source/sdr/properties/connectorproperties.cxx
index 05501095a21c..fc7b278fdb77 100644
--- a/svx/source/sdr/properties/connectorproperties.cxx
+++ b/svx/source/sdr/properties/connectorproperties.cxx
@@ -38,7 +38,7 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// range from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
@@ -46,10 +46,7 @@ namespace sdr
SDRATTR_EDGE_FIRST, SDRATTR_EDGE_LAST,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
ConnectorProperties::ConnectorProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/customshapeproperties.cxx b/svx/source/sdr/properties/customshapeproperties.cxx
index f674ab5b51b0..05e28368f529 100644
--- a/svx/source/sdr/properties/customshapeproperties.cxx
+++ b/svx/source/sdr/properties/customshapeproperties.cxx
@@ -67,7 +67,7 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// ranges from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
@@ -81,10 +81,7 @@ namespace sdr
SDRATTR_CUSTOMSHAPE_FIRST, SDRATTR_CUSTOMSHAPE_LAST,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
bool CustomShapeProperties::AllowItemChange(const sal_uInt16 nWhich, const SfxPoolItem* pNewItem ) const
diff --git a/svx/source/sdr/properties/defaultproperties.cxx b/svx/source/sdr/properties/defaultproperties.cxx
index ce5d927ba270..167e368382c4 100644
--- a/svx/source/sdr/properties/defaultproperties.cxx
+++ b/svx/source/sdr/properties/defaultproperties.cxx
@@ -96,7 +96,7 @@ namespace sdr
ItemChange(nWhichID, &rItem);
PostItemChange(nWhichID);
- SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), nWhichID, nWhichID);
+ SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), {{nWhichID, nWhichID}});
aSet.Put(rItem);
ItemSetChanged(aSet);
}
@@ -121,7 +121,7 @@ namespace sdr
if(nWhich)
{
- SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), nWhich, nWhich, 0, 0);
+ SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), {{nWhich, nWhich}});
ItemSetChanged(aSet);
}
}
@@ -142,7 +142,7 @@ namespace sdr
const SfxPoolItem *pPoolItem;
std::vector< sal_uInt16 > aPostItemChangeList;
bool bDidChange(false);
- SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), SDRATTR_START, EE_ITEMS_END);
+ SfxItemSet aSet(GetSdrObject().GetObjectItemPool(), svl::Items<SDRATTR_START, EE_ITEMS_END>{});
// give a hint to STL_Vector
aPostItemChangeList.reserve(rSet.Count());
diff --git a/svx/source/sdr/properties/e3dcompoundproperties.cxx b/svx/source/sdr/properties/e3dcompoundproperties.cxx
index 5b24f56273ae..7da70b568254 100644
--- a/svx/source/sdr/properties/e3dcompoundproperties.cxx
+++ b/svx/source/sdr/properties/e3dcompoundproperties.cxx
@@ -58,7 +58,7 @@ namespace sdr
GetObjectItemSet();
// add filtered scene properties (SDRATTR_3DSCENE_) to local itemset
- SfxItemSet aSet(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
+ SfxItemSet aSet(*mpItemSet->GetPool(), svl::Items<SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST>{});
aSet.Put(pScene->GetProperties().GetObjectItemSet());
mpItemSet->Put(aSet);
}
@@ -79,7 +79,7 @@ namespace sdr
GetObjectItemSet();
// Generate filtered scene properties (SDRATTR_3DSCENE_) itemset
- SfxItemSet aSet(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
+ SfxItemSet aSet(*mpItemSet->GetPool(), svl::Items<SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST>{});
aSet.Put(rSet);
if(bClearAllItems)
diff --git a/svx/source/sdr/properties/e3dproperties.cxx b/svx/source/sdr/properties/e3dproperties.cxx
index 2a674886e570..e22c10d2ed5f 100644
--- a/svx/source/sdr/properties/e3dproperties.cxx
+++ b/svx/source/sdr/properties/e3dproperties.cxx
@@ -36,15 +36,12 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// ranges from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
// ranges from E3dObject, contains object and scene because of GetMergedItemSet()
- SDRATTR_3D_FIRST, SDRATTR_3D_LAST,
-
- // end
- 0, 0);
+ SDRATTR_3D_FIRST, SDRATTR_3D_LAST>{});
}
E3dProperties::E3dProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/e3dsceneproperties.cxx b/svx/source/sdr/properties/e3dsceneproperties.cxx
index f7e459ac66ed..2639a96d9e7a 100644
--- a/svx/source/sdr/properties/e3dsceneproperties.cxx
+++ b/svx/source/sdr/properties/e3dsceneproperties.cxx
@@ -55,7 +55,7 @@ namespace sdr
if(mpItemSet)
{
// filter for SDRATTR_3DSCENE_ items, only keep those items
- SfxItemSet aNew(*mpItemSet->GetPool(), SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST);
+ SfxItemSet aNew(*mpItemSet->GetPool(), svl::Items<SDRATTR_3DSCENE_FIRST, SDRATTR_3DSCENE_LAST>{});
aNew.Put(*mpItemSet);
mpItemSet->ClearItem();
mpItemSet->Put(aNew);
diff --git a/svx/source/sdr/properties/graphicproperties.cxx b/svx/source/sdr/properties/graphicproperties.cxx
index 955384961f70..8ea829f85c5b 100644
--- a/svx/source/sdr/properties/graphicproperties.cxx
+++ b/svx/source/sdr/properties/graphicproperties.cxx
@@ -39,7 +39,7 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// range from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
@@ -47,10 +47,7 @@ namespace sdr
SDRATTR_GRAF_FIRST, SDRATTR_GRAF_LAST,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
GraphicProperties::GraphicProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/measureproperties.cxx b/svx/source/sdr/properties/measureproperties.cxx
index 03f10aeda774..3b1ae3ee3fda 100644
--- a/svx/source/sdr/properties/measureproperties.cxx
+++ b/svx/source/sdr/properties/measureproperties.cxx
@@ -44,7 +44,7 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// range from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
@@ -52,10 +52,7 @@ namespace sdr
SDRATTR_MEASURE_FIRST, SDRATTR_MEASURE_LAST,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
MeasureProperties::MeasureProperties(SdrObject& rObj)
diff --git a/svx/source/sdr/properties/textproperties.cxx b/svx/source/sdr/properties/textproperties.cxx
index 4749a1c02506..76317ca6683c 100644
--- a/svx/source/sdr/properties/textproperties.cxx
+++ b/svx/source/sdr/properties/textproperties.cxx
@@ -50,15 +50,12 @@ namespace sdr
return o3tl::make_unique<SfxItemSet>(rPool,
// range from SdrAttrObj
- SDRATTR_START, SDRATTR_SHADOW_LAST,
+ svl::Items<SDRATTR_START, SDRATTR_SHADOW_LAST,
SDRATTR_MISC_FIRST, SDRATTR_MISC_LAST,
SDRATTR_TEXTDIRECTION, SDRATTR_TEXTDIRECTION,
// range from SdrTextObj
- EE_ITEMS_START, EE_ITEMS_END,
-
- // end
- 0, 0);
+ EE_ITEMS_START, EE_ITEMS_END>{});
}
TextProperties::TextProperties(SdrObject& rObj)
@@ -483,7 +480,7 @@ namespace sdr
if(bHasURL)
{
- SfxItemSet aColorSet(*aSet.GetPool(), EE_CHAR_COLOR, EE_CHAR_COLOR );
+ SfxItemSet aColorSet(*aSet.GetPool(), svl::Items<EE_CHAR_COLOR, EE_CHAR_COLOR>{} );
aColorSet.Put(aSet, false);
ESelection aSel(nPara, 0);