diff options
author | Jochen Nitschke <j.nitschke+logerrit@ok.de> | 2017-07-06 19:36:34 +0200 |
---|---|---|
committer | Noel Grandin <noel.grandin@collabora.co.uk> | 2017-07-07 22:01:01 +0200 |
commit | c5e4534808c03ce30c7b3e4bbed38ed5fca2d77f (patch) | |
tree | de059f4b070448e25f0f6e75d86618b307ebde6e | |
parent | 6c4224b7ac9d8b016759ae8b5c0afdbef473a16f (diff) |
remove nullptr checks on STL search result iterators
results are in the range of first_iterator to last_iterator.
If one of those is nullptr the algorithm would fail anyway.
This removes some impossible checks in
sw/source/core/unocore/unochart.cxx:
SwChartDataProvider::detectArguments.
A sorted range still holds the same values and has
the same length as the original range.
Replacing raw pointers eases reading this code.
Change-Id: If96bd11e9167488346a57e9e08507ac42338d3cd
Reviewed-on: https://gerrit.libreoffice.org/39683
Tested-by: Jenkins <ci@libreoffice.org>
Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
-rw-r--r-- | chart2/qa/extras/chart2export.cxx | 1 | ||||
-rw-r--r-- | chart2/source/controller/main/DrawCommandDispatch.cxx | 2 | ||||
-rw-r--r-- | comphelper/source/property/property.cxx | 4 | ||||
-rw-r--r-- | connectivity/source/commontools/dbtools.cxx | 4 | ||||
-rw-r--r-- | connectivity/source/commontools/dbtools2.cxx | 2 | ||||
-rw-r--r-- | dbaccess/source/ui/misc/UITools.cxx | 4 | ||||
-rw-r--r-- | extensions/source/propctrlr/cellbindinghelper.cxx | 2 | ||||
-rw-r--r-- | sw/source/core/unocore/unochart.cxx | 17 |
8 files changed, 15 insertions, 21 deletions
diff --git a/chart2/qa/extras/chart2export.cxx b/chart2/qa/extras/chart2export.cxx index 89ae67d570d6..11f37235835b 100644 --- a/chart2/qa/extras/chart2export.cxx +++ b/chart2/qa/extras/chart2export.cxx @@ -205,7 +205,6 @@ OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAcc uno::Sequence<OUString> aNames = xNames->getElementNames(); OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir)); - CPPUNIT_ASSERT(pElement); CPPUNIT_ASSERT(pElement != aNames.end()); return *pElement; } diff --git a/chart2/source/controller/main/DrawCommandDispatch.cxx b/chart2/source/controller/main/DrawCommandDispatch.cxx index cded08bb68c8..d990e351bbd1 100644 --- a/chart2/source/controller/main/DrawCommandDispatch.cxx +++ b/chart2/source/controller/main/DrawCommandDispatch.cxx @@ -363,7 +363,7 @@ void DrawCommandDispatch::execute( const OUString& rCommand, const Sequence< bea [&sKeyModifier](const beans::PropertyValue& lhs) {return lhs.Name == sKeyModifier;} ); sal_Int16 nKeyModifier = 0; - if ( pKeyModifier != pEnd && pKeyModifier && ( pKeyModifier->Value >>= nKeyModifier ) && nKeyModifier == KEY_MOD1 ) + if ( pKeyModifier != pEnd && ( pKeyModifier->Value >>= nKeyModifier ) && nKeyModifier == KEY_MOD1 ) { if ( eDrawMode == CHARTDRAW_INSERT ) { diff --git a/comphelper/source/property/property.cxx b/comphelper/source/property/property.cxx index d5ddc9a9ab7b..a0083908246f 100644 --- a/comphelper/source/property/property.cxx +++ b/comphelper/source/property/property.cxx @@ -149,7 +149,7 @@ void RemoveProperty(Sequence<Property>& _rProps, const OUString& _rPropName) Property aNameProp(_rPropName, 0, Type(), 0); const Property* pResult = std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); - if ( pResult && (pResult != pProperties + nLen) && (pResult->Name == _rPropName) ) + if ( pResult != _rProps.end() && pResult->Name == _rPropName ) { OSL_ENSURE(pResult->Name.equals(_rPropName), "::RemoveProperty Properties not sorted"); removeElementAt(_rProps, pResult - pProperties); @@ -166,7 +166,7 @@ void ModifyPropertyAttributes(Sequence<Property>& seqProps, const OUString& sPro Property aNameProp(sPropName, 0, Type(), 0); Property* pResult = std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); - if ( pResult && (pResult != pProperties + nLen) && (pResult->Name == sPropName) ) + if ( (pResult != seqProps.end()) && (pResult->Name == sPropName) ) { pResult->Attributes |= nAddAttrib; pResult->Attributes &= ~nRemoveAttrib; diff --git a/connectivity/source/commontools/dbtools.cxx b/connectivity/source/commontools/dbtools.cxx index 109217552183..23905d80f14a 100644 --- a/connectivity/source/commontools/dbtools.cxx +++ b/connectivity/source/commontools/dbtools.cxx @@ -962,8 +962,8 @@ try Property* pResult = std::lower_bound( pNewProps, pNewProps + nNewLen, pOldProps[i], ::comphelper::PropertyCompareByName()); - if ( pResult - && ( pResult != pNewProps + nNewLen && pResult->Name == pOldProps[i].Name ) + if ( ( pResult != aNewProperties.end() ) + && ( pResult->Name == pOldProps[i].Name ) && ( (pResult->Attributes & PropertyAttribute::READONLY) == 0 ) && ( pResult->Type.equals(pOldProps[i].Type)) ) { // Attributes match and the property is not read-only diff --git a/connectivity/source/commontools/dbtools2.cxx b/connectivity/source/commontools/dbtools2.cxx index c732d84fcf53..6f829f4f272b 100644 --- a/connectivity/source/commontools/dbtools2.cxx +++ b/connectivity/source/commontools/dbtools2.cxx @@ -641,7 +641,7 @@ bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp, const OUSt aInfo.end(), [&_sProperty](const PropertyValue& lhs) { return lhs.Name == _sProperty; }); - if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) ) + if ( pValue != aInfo.end() ) pValue->Value >>= bEnabled; } } diff --git a/dbaccess/source/ui/misc/UITools.cxx b/dbaccess/source/ui/misc/UITools.cxx index eefea14eebe9..f2e2cabb553b 100644 --- a/dbaccess/source/ui/misc/UITools.cxx +++ b/dbaccess/source/ui/misc/UITools.cxx @@ -1038,13 +1038,13 @@ void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource, [](const PropertyValue& lhs) {return TPropertyValueEqualFunctor()(lhs, PROPERTY_AUTOINCREMENTCREATION);} ); - if ( pValue && pValue != aInfo.end() ) + if ( pValue != aInfo.end() ) pValue->Value >>= _rsAutoIncrementValue; pValue =std::find_if(aInfo.begin(), aInfo.end(), [](const PropertyValue& lhs) {return TPropertyValueEqualFunctor()(lhs, "IsAutoRetrievingEnabled");} ); - if ( pValue && pValue != aInfo.end() ) + if ( pValue != aInfo.end() ) pValue->Value >>= _rAutoIncrementValueEnabled; } } diff --git a/extensions/source/propctrlr/cellbindinghelper.cxx b/extensions/source/propctrlr/cellbindinghelper.cxx index 0a20acec0ac5..6852d76fe385 100644 --- a/extensions/source/propctrlr/cellbindinghelper.cxx +++ b/extensions/source/propctrlr/cellbindinghelper.cxx @@ -386,7 +386,7 @@ namespace pcr aAvailableServices.end(), StringCompare( _rService ) ); - if ( pFound - aAvailableServices.getConstArray() < aAvailableServices.getLength() ) + if ( pFound != aAvailableServices.end() ) { bYesItIs = true; } diff --git a/sw/source/core/unocore/unochart.cxx b/sw/source/core/unocore/unochart.cxx index 5ea7bf64624a..d9ae48983a5d 100644 --- a/sw/source/core/unocore/unochart.cxx +++ b/sw/source/core/unocore/unochart.cxx @@ -1288,20 +1288,15 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwChartDataProvider::detectArgume // build value for 'SequenceMapping' uno::Sequence< sal_Int32 > aSortedMapping( aSequenceMapping ); - sal_Int32 *pSortedMapping = aSortedMapping.getArray(); - std::sort( pSortedMapping, pSortedMapping + aSortedMapping.getLength() ); - OSL_ENSURE( aSortedMapping.getLength() == nNumDS_LDS, "unexpected size of sequence" ); + std::sort( aSortedMapping.begin(), aSortedMapping.end() ); bool bNeedSequenceMapping = false; - for (sal_Int32 i = 0; i < nNumDS_LDS; ++i) + for (sal_Int32 i = 0; i < aSequenceMapping.getLength(); ++i) { - sal_Int32 *pIt = std::find( pSortedMapping, pSortedMapping + nNumDS_LDS, - pSequenceMapping[i] ); - OSL_ENSURE( pIt, "index not found" ); - if (!pIt) - return aResult; // failed -> return empty property sequence - pSequenceMapping[i] = pIt - pSortedMapping; + auto it = std::find( aSortedMapping.begin(), aSortedMapping.end(), + aSequenceMapping[i] ); + aSequenceMapping[i] = std::distance(aSortedMapping.begin(), it); - if (i != pSequenceMapping[i]) + if (i != aSequenceMapping[i]) bNeedSequenceMapping = true; } |