From 668fbdfe27b25e1ab001206781b0a8d0166a6162 Mon Sep 17 00:00:00 2001 From: Nyall Dawson Date: Mon, 16 Dec 2024 11:31:19 +1000 Subject: [PATCH] Fix coverity nullptr dereference warning --- src/providers/wfs/qgswfsfeatureiterator.cpp | 56 +++++++++++---------- 1 file changed, 29 insertions(+), 27 deletions(-) diff --git a/src/providers/wfs/qgswfsfeatureiterator.cpp b/src/providers/wfs/qgswfsfeatureiterator.cpp index e844917a8326..97e833677b2e 100644 --- a/src/providers/wfs/qgswfsfeatureiterator.cpp +++ b/src/providers/wfs/qgswfsfeatureiterator.cpp @@ -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( g ); - bool allExpectedType = true; - for ( int i = 0; i < gc->numGeometries(); ++i ) + const QgsAbstractGeometry *g = f.geometry().constGet(); + if ( const QgsGeometryCollection *gc = qgsgeometry_cast( 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 )