Kaydet (Commit) c5e45348 authored tarafından Jochen Nitschke's avatar Jochen Nitschke Kaydeden (comit) Noel Grandin

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/39683Tested-by: 's avatarJenkins <ci@libreoffice.org>
Reviewed-by: 's avatarNoel Grandin <noel.grandin@collabora.co.uk>
üst 6c4224b7
...@@ -205,7 +205,6 @@ OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAcc ...@@ -205,7 +205,6 @@ OUString findChartFile(const OUString& rDir, uno::Reference< container::XNameAcc
uno::Sequence<OUString> aNames = xNames->getElementNames(); uno::Sequence<OUString> aNames = xNames->getElementNames();
OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir)); OUString* pElement = std::find_if(aNames.begin(), aNames.end(), CheckForChartName(rDir));
CPPUNIT_ASSERT(pElement);
CPPUNIT_ASSERT(pElement != aNames.end()); CPPUNIT_ASSERT(pElement != aNames.end());
return *pElement; return *pElement;
} }
......
...@@ -363,7 +363,7 @@ void DrawCommandDispatch::execute( const OUString& rCommand, const Sequence< bea ...@@ -363,7 +363,7 @@ void DrawCommandDispatch::execute( const OUString& rCommand, const Sequence< bea
[&sKeyModifier](const beans::PropertyValue& lhs) [&sKeyModifier](const beans::PropertyValue& lhs)
{return lhs.Name == sKeyModifier;} ); {return lhs.Name == sKeyModifier;} );
sal_Int16 nKeyModifier = 0; 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 ) if ( eDrawMode == CHARTDRAW_INSERT )
{ {
......
...@@ -149,7 +149,7 @@ void RemoveProperty(Sequence<Property>& _rProps, const OUString& _rPropName) ...@@ -149,7 +149,7 @@ void RemoveProperty(Sequence<Property>& _rProps, const OUString& _rPropName)
Property aNameProp(_rPropName, 0, Type(), 0); Property aNameProp(_rPropName, 0, Type(), 0);
const Property* pResult = std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); 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"); OSL_ENSURE(pResult->Name.equals(_rPropName), "::RemoveProperty Properties not sorted");
removeElementAt(_rProps, pResult - pProperties); removeElementAt(_rProps, pResult - pProperties);
...@@ -166,7 +166,7 @@ void ModifyPropertyAttributes(Sequence<Property>& seqProps, const OUString& sPro ...@@ -166,7 +166,7 @@ void ModifyPropertyAttributes(Sequence<Property>& seqProps, const OUString& sPro
Property aNameProp(sPropName, 0, Type(), 0); Property aNameProp(sPropName, 0, Type(), 0);
Property* pResult = std::lower_bound(pProperties, pProperties + nLen, aNameProp, PropertyCompareByName()); 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 |= nAddAttrib;
pResult->Attributes &= ~nRemoveAttrib; pResult->Attributes &= ~nRemoveAttrib;
......
...@@ -962,8 +962,8 @@ try ...@@ -962,8 +962,8 @@ try
Property* pResult = std::lower_bound( Property* pResult = std::lower_bound(
pNewProps, pNewProps + nNewLen, pOldProps[i], ::comphelper::PropertyCompareByName()); pNewProps, pNewProps + nNewLen, pOldProps[i], ::comphelper::PropertyCompareByName());
if ( pResult if ( ( pResult != aNewProperties.end() )
&& ( pResult != pNewProps + nNewLen && pResult->Name == pOldProps[i].Name ) && ( pResult->Name == pOldProps[i].Name )
&& ( (pResult->Attributes & PropertyAttribute::READONLY) == 0 ) && ( (pResult->Attributes & PropertyAttribute::READONLY) == 0 )
&& ( pResult->Type.equals(pOldProps[i].Type)) ) && ( pResult->Type.equals(pOldProps[i].Type)) )
{ // Attributes match and the property is not read-only { // Attributes match and the property is not read-only
......
...@@ -641,7 +641,7 @@ bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp, const OUSt ...@@ -641,7 +641,7 @@ bool isDataSourcePropertyEnabled(const Reference<XInterface>& _xProp, const OUSt
aInfo.end(), aInfo.end(),
[&_sProperty](const PropertyValue& lhs) [&_sProperty](const PropertyValue& lhs)
{ return lhs.Name == _sProperty; }); { return lhs.Name == _sProperty; });
if ( pValue && pValue != (aInfo.getConstArray() + aInfo.getLength()) ) if ( pValue != aInfo.end() )
pValue->Value >>= bEnabled; pValue->Value >>= bEnabled;
} }
} }
......
...@@ -1038,13 +1038,13 @@ void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource, ...@@ -1038,13 +1038,13 @@ void fillAutoIncrementValue(const Reference<XPropertySet>& _xDatasource,
[](const PropertyValue& lhs) [](const PropertyValue& lhs)
{return TPropertyValueEqualFunctor()(lhs, PROPERTY_AUTOINCREMENTCREATION);} ); {return TPropertyValueEqualFunctor()(lhs, PROPERTY_AUTOINCREMENTCREATION);} );
if ( pValue && pValue != aInfo.end() ) if ( pValue != aInfo.end() )
pValue->Value >>= _rsAutoIncrementValue; pValue->Value >>= _rsAutoIncrementValue;
pValue =std::find_if(aInfo.begin(), aInfo.end(), pValue =std::find_if(aInfo.begin(), aInfo.end(),
[](const PropertyValue& lhs) [](const PropertyValue& lhs)
{return TPropertyValueEqualFunctor()(lhs, "IsAutoRetrievingEnabled");} ); {return TPropertyValueEqualFunctor()(lhs, "IsAutoRetrievingEnabled");} );
if ( pValue && pValue != aInfo.end() ) if ( pValue != aInfo.end() )
pValue->Value >>= _rAutoIncrementValueEnabled; pValue->Value >>= _rAutoIncrementValueEnabled;
} }
} }
......
...@@ -386,7 +386,7 @@ namespace pcr ...@@ -386,7 +386,7 @@ namespace pcr
aAvailableServices.end(), aAvailableServices.end(),
StringCompare( _rService ) StringCompare( _rService )
); );
if ( pFound - aAvailableServices.getConstArray() < aAvailableServices.getLength() ) if ( pFound != aAvailableServices.end() )
{ {
bYesItIs = true; bYesItIs = true;
} }
......
...@@ -1288,20 +1288,15 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwChartDataProvider::detectArgume ...@@ -1288,20 +1288,15 @@ uno::Sequence< beans::PropertyValue > SAL_CALL SwChartDataProvider::detectArgume
// build value for 'SequenceMapping' // build value for 'SequenceMapping'
uno::Sequence< sal_Int32 > aSortedMapping( aSequenceMapping ); uno::Sequence< sal_Int32 > aSortedMapping( aSequenceMapping );
sal_Int32 *pSortedMapping = aSortedMapping.getArray(); std::sort( aSortedMapping.begin(), aSortedMapping.end() );
std::sort( pSortedMapping, pSortedMapping + aSortedMapping.getLength() );
OSL_ENSURE( aSortedMapping.getLength() == nNumDS_LDS, "unexpected size of sequence" );
bool bNeedSequenceMapping = false; 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, auto it = std::find( aSortedMapping.begin(), aSortedMapping.end(),
pSequenceMapping[i] ); aSequenceMapping[i] );
OSL_ENSURE( pIt, "index not found" ); aSequenceMapping[i] = std::distance(aSortedMapping.begin(), it);
if (!pIt)
return aResult; // failed -> return empty property sequence
pSequenceMapping[i] = pIt - pSortedMapping;
if (i != pSequenceMapping[i]) if (i != aSequenceMapping[i])
bNeedSequenceMapping = true; bNeedSequenceMapping = true;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment