summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorNoel Grandin <noelgrandin@gmail.com>2021-01-02 20:35:33 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-01-03 08:53:17 +0100
commit3140d30ba56b95536e9f92ef3074579524791fe5 (patch)
tree47f57f036133ad06b4fff5ce63c842c40af0e4ef /svx
parentf4e8c28e465d103a7ac4bc711e3b23ad3cae9996 (diff)
tighten up asserting in SfxPoolItem::operator==
...subclasses, so we always call the SfxPoolItem::operatar== which will ensure that we are always comparing two objects that belong to the same class. And fix the fallout in SvxUnoNameItemTable. Change-Id: I5ec7fedaa914a328897b54c016ad13e505a15937 Reviewed-on: https://gerrit.libreoffice.org/c/core/+/108599 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/items/chrtitem.cxx1
-rw-r--r--svx/source/unodraw/UnoNameItemTable.cxx25
2 files changed, 24 insertions, 2 deletions
diff --git a/svx/source/items/chrtitem.cxx b/svx/source/items/chrtitem.cxx
index c8f502e38e3e..9ee289ea083b 100644
--- a/svx/source/items/chrtitem.cxx
+++ b/svx/source/items/chrtitem.cxx
@@ -122,6 +122,7 @@ bool SvxDoubleItem::GetPresentation
bool SvxDoubleItem::operator == (const SfxPoolItem& rItem) const
{
+ assert(SfxPoolItem::operator==(rItem));
return static_cast<const SvxDoubleItem&>(rItem).fVal == fVal;
}
diff --git a/svx/source/unodraw/UnoNameItemTable.cxx b/svx/source/unodraw/UnoNameItemTable.cxx
index 612877880ada..e8038e25a9f5 100644
--- a/svx/source/unodraw/UnoNameItemTable.cxx
+++ b/svx/source/unodraw/UnoNameItemTable.cxx
@@ -36,6 +36,27 @@
using namespace ::com::sun::star;
using namespace ::cppu;
+namespace
+{
+ // We need to override operator== here and specifically bypass the assert
+ // in SfxPoolItem::operator== in order to make the FindItemSurrogate call
+ // in SvxUnoNameItemTable::hasByName safe.
+ class SampleItem : public NameOrIndex
+ {
+ public:
+ SampleItem(sal_uInt16 nWhich, const OUString& rName) : NameOrIndex(nWhich, rName) {}
+
+ bool operator==(const SfxPoolItem& rCmp) const
+ {
+ assert(dynamic_cast<const NameOrIndex*>(&rCmp) && "comparing different pool item subclasses");
+ auto const & rOther = static_cast<const NameOrIndex&>(rCmp);
+ return GetName() == rOther.GetName() && GetPalIndex() == rOther.GetPalIndex();
+ }
+ };
+
+}
+
+
SvxUnoNameItemTable::SvxUnoNameItemTable( SdrModel* pModel, sal_uInt16 nWhich, sal_uInt8 nMemberId ) throw()
: mpModel( pModel ),
mpModelPool( pModel ? &pModel->GetItemPool() : nullptr ),
@@ -187,7 +208,7 @@ uno::Any SAL_CALL SvxUnoNameItemTable::getByName( const OUString& aApiName )
if (mpModelPool && !aName.isEmpty())
{
- NameOrIndex aSample(mnWhich, aName);
+ SampleItem aSample(mnWhich, aName);
for (const SfxPoolItem* pFindItem : mpModelPool->FindItemSurrogate(mnWhich, aSample))
if (isValid(static_cast<const NameOrIndex*>(pFindItem)))
{
@@ -234,7 +255,7 @@ sal_Bool SAL_CALL SvxUnoNameItemTable::hasByName( const OUString& aApiName )
if (!mpModelPool)
return false;
- NameOrIndex aSample(mnWhich, aName);
+ SampleItem aSample(mnWhich, aName);
for (const SfxPoolItem* pFindItem : mpModelPool->FindItemSurrogate(mnWhich, aSample))
if (isValid(static_cast<const NameOrIndex*>(pFindItem)))
return true;