Skip to content

Commit

Permalink
Fix Coverity null pointer dereference issues
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Nov 11, 2017
1 parent a9145f1 commit 5a6c222
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 22 deletions.
34 changes: 13 additions & 21 deletions src/analysis/vector/geometry_checker/qgsgeometryoverlapcheck.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
error->setObsolete();
return;
}
QgsAbstractGeometry *interGeom = geomEngineA->intersection( layerFeatureB.geometry(), &errMsg );
std::unique_ptr< QgsAbstractGeometry > interGeom( geomEngineA->intersection( layerFeatureB.geometry(), &errMsg ) );
if ( !interGeom )
{
error->setFixFailed( tr( "Failed to compute intersection between overlapping features: %1" ).arg( errMsg ) );
Expand All @@ -109,7 +109,7 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
QgsAbstractGeometry *interPart = nullptr;
for ( int iPart = 0, nParts = interGeom->partCount(); iPart < nParts; ++iPart )
{
QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( interGeom, iPart );
QgsAbstractGeometry *part = QgsGeometryCheckerUtils::getGeomPart( interGeom.get(), iPart );
if ( std::fabs( part->area() - overlapError->value().toDouble() ) < mContext->reducedTolerance &&
QgsGeometryCheckerUtils::pointsFuzzyEqual( part->centroid(), overlapError->location(), mContext->reducedTolerance ) )
{
Expand All @@ -119,7 +119,6 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
}
if ( !interPart || interPart->isEmpty() )
{
delete interGeom;
error->setObsolete();
return;
}
Expand All @@ -131,30 +130,28 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
}
else if ( method == Subtract )
{
QgsAbstractGeometry *diff1 = geomEngineA->difference( interPart, &errMsg );
std::unique_ptr< QgsAbstractGeometry > diff1( geomEngineA->difference( interPart, &errMsg ) );
if ( !diff1 || diff1->isEmpty() )
{
delete diff1;
diff1 = nullptr;
diff1.reset();
}
else
{
QgsGeometryCheckerUtils::filter1DTypes( diff1 );
QgsGeometryCheckerUtils::filter1DTypes( diff1.get() );
}
std::unique_ptr< QgsGeometryEngine > geomEngineB = QgsGeometryCheckerUtils::createGeomEngine( layerFeatureB.geometry(), mContext->reducedTolerance );
QgsAbstractGeometry *diff2 = geomEngineB->difference( interPart, &errMsg );
std::unique_ptr< QgsAbstractGeometry > diff2( geomEngineB->difference( interPart, &errMsg ) );
if ( !diff2 || diff2->isEmpty() )
{
delete diff2;
diff2 = nullptr;
diff2.reset();
}
else
{
QgsGeometryCheckerUtils::filter1DTypes( diff2 );
QgsGeometryCheckerUtils::filter1DTypes( diff2.get() );
}
double shared1 = diff1 ? QgsGeometryCheckerUtils::sharedEdgeLength( diff1, interPart, mContext->reducedTolerance ) : 0;
double shared2 = diff2 ? QgsGeometryCheckerUtils::sharedEdgeLength( diff2, interPart, mContext->reducedTolerance ) : 0;
if ( shared1 == 0. || shared2 == 0. )
double shared1 = diff1 ? QgsGeometryCheckerUtils::sharedEdgeLength( diff1.get(), interPart, mContext->reducedTolerance ) : 0;
double shared2 = diff2 ? QgsGeometryCheckerUtils::sharedEdgeLength( diff2.get(), interPart, mContext->reducedTolerance ) : 0;
if ( !diff1 || !diff2 || shared1 == 0. || shared2 == 0. )
{
error->setFixFailed( tr( "Could not find shared edges between intersection and overlapping features" ) );
}
Expand All @@ -163,32 +160,27 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
if ( shared1 < shared2 )
{
diff1->transform( featurePoolA->getLayerToMapTransform(), QgsCoordinateTransform::ReverseTransform );
featureA.setGeometry( QgsGeometry( diff1 ) );
diff1 = 0;
featureA.setGeometry( QgsGeometry( std::move( diff1 ) ) );

changes[error->layerId()][featureA.id()].append( Change( ChangeFeature, ChangeChanged ) );
featurePoolA->updateFeature( featureA );
}
else
{
diff2->transform( featurePoolB->getLayerToMapTransform(), QgsCoordinateTransform::ReverseTransform );
featureB.setGeometry( QgsGeometry( diff2 ) );
diff2 = 0;
featureB.setGeometry( QgsGeometry( std::move( diff2 ) ) );

changes[overlapError->overlappedFeature().first][featureB.id()].append( Change( ChangeFeature, ChangeChanged ) );
featurePoolB->updateFeature( featureB );
}

error->setFixed( method );
}
delete diff1;
delete diff2;
}
else
{
error->setFixFailed( tr( "Unknown method" ) );
}
delete interGeom;
}

QStringList QgsGeometryOverlapCheck::getResolutionMethods() const
Expand Down
1 change: 1 addition & 0 deletions src/core/geometry/qgsgeometrymakevalid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -388,6 +388,7 @@ static bool ring_make_geos_friendly( QgsCurve *ring )

// earlier we allowed in only geometries with straight segments
QgsLineString *linestring = qgsgeometry_cast<QgsLineString *>( ring );
Q_ASSERT_X( linestring, "ring_make_geos_friendly", "ring was not a linestring" );

// close the ring if not already closed (2d only)

Expand Down
1 change: 1 addition & 0 deletions src/core/layout/qgslayoutitemgroupundocommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void QgsLayoutItemGroupUndoCommand::switchState()
{
// ungroup
QgsLayoutItemGroup *group = dynamic_cast< QgsLayoutItemGroup * >( mLayout->itemByUuid( mGroupUuid ) );
Q_ASSERT_X( group, "QgsLayoutItemGroupUndoCommand::switchState", "Could not find group" );
group->removeItems();
mLayout->removeLayoutItemPrivate( group );
mState = Ungrouped;
Expand Down
3 changes: 2 additions & 1 deletion src/gui/qgsattributeform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -897,7 +897,8 @@ void QgsAttributeForm::onConstraintStatusChanged( const QString &constraint,

QgsAttributeFormEditorWidget *formEditorWidget = mFormEditorWidgets.value( eww->fieldIdx() );

formEditorWidget->setConstraintStatus( constraint, description, err, result );
if ( formEditorWidget )
formEditorWidget->setConstraintStatus( constraint, description, err, result );
}

QList<QgsEditorWidgetWrapper *> QgsAttributeForm::constraintDependencies( QgsEditorWidgetWrapper *w )
Expand Down

0 comments on commit 5a6c222

Please sign in to comment.