From 9890c98480161040e048f37d94004b7b05f6c79f Mon Sep 17 00:00:00 2001 From: Tor Lillqvist Date: Wed, 17 Aug 2011 18:35:21 +0300 Subject: Fix dubious std::lower_bound() usage that breaks a _DEBUG MSVC build Always pass the value to search for of type equal to what the iterators return. --- comphelper/inc/comphelper/property.hxx | 13 ----------- comphelper/source/property/propagg.cxx | 3 ++- comphelper/source/property/property.cxx | 6 +++-- .../source/property/propertycontainerhelper.cxx | 26 +++++++++------------- 4 files changed, 16 insertions(+), 32 deletions(-) diff --git a/comphelper/inc/comphelper/property.hxx b/comphelper/inc/comphelper/property.hxx index 662fa84903b8..a294b3363b5d 100644 --- a/comphelper/inc/comphelper/property.hxx +++ b/comphelper/inc/comphelper/property.hxx @@ -51,19 +51,6 @@ namespace comphelper /** compare two properties by name */ - struct PropertyStringLessFunctor : ::std::binary_function< ::com::sun::star::beans::Property, ::rtl::OUString, bool > - { - // ................................................................ - inline bool operator()( const ::com::sun::star::beans::Property& lhs, const ::rtl::OUString& rhs ) const - { - return lhs.Name.compareTo(rhs) < 0; - } - // ................................................................ - inline bool operator()( const ::rtl::OUString& lhs, const ::com::sun::star::beans::Property& rhs ) const - { - return lhs.compareTo(rhs.Name) < 0; - } - }; //-------------------------------------------------------------------------- // comparing two property instances struct PropertyCompareByName : public ::std::binary_function< ::com::sun::star::beans::Property, ::com::sun::star::beans::Property, bool > diff --git a/comphelper/source/property/propagg.cxx b/comphelper/source/property/propagg.cxx index b83c292689dc..945ace837808 100644 --- a/comphelper/source/property/propagg.cxx +++ b/comphelper/source/property/propagg.cxx @@ -60,7 +60,8 @@ namespace comphelper { sal_Int32 nLen = _rProps.getLength(); const Property* pProperties = _rProps.getConstArray(); - const Property* pResult = ::std::lower_bound(pProperties, pProperties + nLen,_rName, ::comphelper::PropertyStringLessFunctor()); + Property aNameProp(_rName, 0, Type(), 0); + const Property* pResult = ::std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); if ( pResult && ( pResult == pProperties + nLen || pResult->Name != _rName) ) pResult = NULL; diff --git a/comphelper/source/property/property.cxx b/comphelper/source/property/property.cxx index 37bb62cc98ef..b20eba9c47f9 100644 --- a/comphelper/source/property/property.cxx +++ b/comphelper/source/property/property.cxx @@ -180,7 +180,8 @@ void RemoveProperty(Sequence& _rProps, const rtl::OUString& _rPropName // binaere Suche const Property* pProperties = _rProps.getConstArray(); - const Property* pResult = ::std::lower_bound(pProperties, pProperties + nLen, _rPropName,PropertyStringLessFunctor()); + Property aNameProp(_rPropName, 0, Type(), 0); + const Property* pResult = ::std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); // gefunden ? if ( pResult && (pResult != pProperties + nLen) && (pResult->Name == _rPropName) ) @@ -197,7 +198,8 @@ void ModifyPropertyAttributes(Sequence& seqProps, const ::rtl::OUStrin // binaere Suche Property* pProperties = seqProps.getArray(); - Property* pResult = ::std::lower_bound(pProperties, pProperties + nLen,sPropName, PropertyStringLessFunctor()); + Property aNameProp(sPropName, 0, Type(), 0); + Property* pResult = ::std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); // gefunden ? if ( pResult && (pResult != pProperties + nLen) && (pResult->Name == sPropName) ) diff --git a/comphelper/source/property/propertycontainerhelper.cxx b/comphelper/source/property/propertycontainerhelper.cxx index 6233efbc011f..b984c3a2e635 100644 --- a/comphelper/source/property/propertycontainerhelper.cxx +++ b/comphelper/source/property/propertycontainerhelper.cxx @@ -60,15 +60,11 @@ namespace } }; // comparing two property descriptions - struct PropertyDescriptionHandleCompare : public ::std::binary_function< PropertyDescription, sal_Int32, bool > + struct PropertyDescriptionHandleCompare : public ::std::binary_function< PropertyDescription, PropertyDescription, bool > { - bool operator() (const PropertyDescription& x, const sal_Int32& y) const - { - return x.aProperty.Handle < y; - } - bool operator() (const sal_Int32& x, const PropertyDescription& y) const + bool operator() (const PropertyDescription& x, const PropertyDescription& y) const { - return x < y.aProperty.Handle; + return x.aProperty.Handle < y.aProperty.Handle; } }; // comparing two property descriptions (by name) @@ -194,15 +190,11 @@ sal_Bool OPropertyContainerHelper::isRegisteredProperty( const ::rtl::OUString& //-------------------------------------------------------------------------- namespace { - struct ComparePropertyWithHandle + struct ComparePropertyHandles { - bool operator()( const PropertyDescription& _rLHS, sal_Int32 _nRHS ) const - { - return _rLHS.aProperty.Handle < _nRHS; - } - bool operator()( sal_Int32 _nLHS, const PropertyDescription& _rRHS ) const + bool operator()( const PropertyDescription& _rLHS, const PropertyDescription& _nRHS ) const { - return _nLHS < _rRHS.aProperty.Handle; + return _rLHS.aProperty.Handle < _nRHS.aProperty.Handle; } }; } @@ -223,7 +215,7 @@ void OPropertyContainerHelper::implPushBackProperty(const PropertyDescription& _ PropertiesIterator pos = ::std::lower_bound( m_aProperties.begin(), m_aProperties.end(), - _rProp.aProperty.Handle, ComparePropertyWithHandle() ); + _rProp, ComparePropertyHandles() ); m_aProperties.insert( pos, _rProp ); } @@ -466,11 +458,13 @@ void OPropertyContainerHelper::getFastPropertyValue(Any& _rValue, sal_Int32 _nHa //-------------------------------------------------------------------------- OPropertyContainerHelper::PropertiesIterator OPropertyContainerHelper::searchHandle(sal_Int32 _nHandle) { + PropertyDescription aHandlePropDesc; + aHandlePropDesc.aProperty.Handle = _nHandle; // search a lower bound PropertiesIterator aLowerBound = ::std::lower_bound( m_aProperties.begin(), m_aProperties.end(), - _nHandle, + aHandlePropDesc, PropertyDescriptionHandleCompare()); // check for identity -- cgit v1.2.3