Skip to content

Commit

Permalink
Fix coverity nullptr dereference warning
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Dec 16, 2024
1 parent 4f46167 commit 668fbdf
Showing 1 changed file with 29 additions and 27 deletions.
56 changes: 29 additions & 27 deletions src/providers/wfs/qgswfsfeatureiterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -630,38 +630,40 @@ void QgsWFSFeatureDownloaderImpl::run( bool serializeFeatures, long long maxFeat
if ( f.hasGeometry() && f.geometry().wkbType() == Qgis::WkbType::GeometryCollection && ( mShared->mWKBType == Qgis::WkbType::MultiPoint || mShared->mWKBType == Qgis::WkbType::MultiLineString || mShared->mWKBType == Qgis::WkbType::MultiPolygon ) )
{
Qgis::WkbType singleType = QgsWkbTypes::singleType( mShared->mWKBType );
auto g = f.geometry().constGet();
auto gc = qgsgeometry_cast<QgsGeometryCollection *>( g );
bool allExpectedType = true;
for ( int i = 0; i < gc->numGeometries(); ++i )
const QgsAbstractGeometry *g = f.geometry().constGet();
if ( const QgsGeometryCollection *gc = qgsgeometry_cast<const QgsGeometryCollection *>( g ) )
{
if ( gc->geometryN( i )->wkbType() != singleType )
{
allExpectedType = false;
break;
}
}
if ( allExpectedType )
{
QgsGeometryCollection *newGC;
if ( mShared->mWKBType == Qgis::WkbType::MultiPoint )
{
newGC = new QgsMultiPoint();
}
else if ( mShared->mWKBType == Qgis::WkbType::MultiLineString )
{
newGC = new QgsMultiLineString();
}
else
bool allExpectedType = true;
for ( int i = 0; i < gc->numGeometries(); ++i )
{
newGC = new QgsMultiPolygon();
if ( gc->geometryN( i )->wkbType() != singleType )
{
allExpectedType = false;
break;
}
}
newGC->reserve( gc->numGeometries() );
for ( int i = 0; i < gc->numGeometries(); ++i )
if ( allExpectedType )
{
newGC->addGeometry( gc->geometryN( i )->clone() );
QgsGeometryCollection *newGC;
if ( mShared->mWKBType == Qgis::WkbType::MultiPoint )
{
newGC = new QgsMultiPoint();
}
else if ( mShared->mWKBType == Qgis::WkbType::MultiLineString )
{
newGC = new QgsMultiLineString();
}
else
{
newGC = new QgsMultiPolygon();
}
newGC->reserve( gc->numGeometries() );
for ( int i = 0; i < gc->numGeometries(); ++i )
{
newGC->addGeometry( gc->geometryN( i )->clone() );
}
f.setGeometry( QgsGeometry( newGC ) );
}
f.setGeometry( QgsGeometry( newGC ) );
}
}
else if ( f.hasGeometry() && !mShared->mWFSGeometryTypeFilter.isEmpty() && QgsWkbTypes::flatType( f.geometry().wkbType() ) != mShared->mWKBType )
Expand Down

0 comments on commit 668fbdf

Please sign in to comment.