Skip to content
Permalink
Browse files

Fix potential crashes in geometry checker (identified by Coverity)

  • Loading branch information
nyalldawson committed May 28, 2017
1 parent 566d75b commit a9370af19c2ff081c38207973795d7d49e253cc4
@@ -89,6 +89,11 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method,

// Check if error still applies
int n = QgsGeometryCheckerUtils::polyLineSize( geometry, vidx.part, vidx.ring );
if ( n == 0 )
{
error->setObsolete();
return;
}
const QgsPointV2 &p1 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + n ) % n ) );
const QgsPointV2 &p2 = geometry->vertexAt( vidx );
const QgsPointV2 &p3 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) );
@@ -73,6 +73,11 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError *error, int

// Check if error still applies
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
if ( nVerts == 0 )
{
error->setObsolete();
return;
}
QgsPointV2 pi = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + nVerts - 1 ) % nVerts ) );
QgsPointV2 pj = geom->vertexAt( error->vidx() );
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) >= QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance() )
@@ -79,6 +79,12 @@ void QgsGeometrySegmentLengthCheck::fixError( QgsGeometryCheckError *error, int

// Check if error still applies
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
if ( nVerts == 0 )
{
error->setObsolete();
return;
}

QgsPointV2 pi = geom->vertexAt( error->vidx() );
QgsPointV2 pj = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + nVerts ) % nVerts ) );
double dist = qSqrt( QgsGeometryUtils::sqrDistance2D( pi, pj ) );
@@ -110,7 +110,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i
// Check if error still applies
bool ringIsClosed = false;
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring, &ringIsClosed );
if ( inter.segment1 >= nVerts || inter.segment2 >= nVerts )
if ( nVerts == 0 || inter.segment1 >= nVerts || inter.segment2 >= nVerts )
{
error->setObsolete();
return;

0 comments on commit a9370af

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