Skip to content
Permalink
Browse files

Fix Coverity null pointer dereference issues

  • Loading branch information
nyalldawson committed Nov 11, 2017
1 parent a9145f1 commit 5a6c222e87cd288ddb43dde66803cc90527b6e98
@@ -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 ) );
@@ -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 ) )
{
@@ -119,7 +119,6 @@ void QgsGeometryOverlapCheck::fixError( QgsGeometryCheckError *error, int method
}
if ( !interPart || interPart->isEmpty() )
{
delete interGeom;
error->setObsolete();
return;
}
@@ -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" ) );
}
@@ -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
@@ -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)

@@ -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;
@@ -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 )

0 comments on commit 5a6c222

Please sign in to comment.
You can’t perform that action at this time.