Skip to content

Commit a9370af

Browse files
committedMay 28, 2017
Fix potential crashes in geometry checker (identified by Coverity)
1 parent 566d75b commit a9370af

File tree

4 files changed

+17
-1
lines changed

4 files changed

+17
-1
lines changed
 

‎src/plugins/geometry_checker/checks/qgsgeometryanglecheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,11 @@ void QgsGeometryAngleCheck::fixError( QgsGeometryCheckError *error, int method,
8989

9090
// Check if error still applies
9191
int n = QgsGeometryCheckerUtils::polyLineSize( geometry, vidx.part, vidx.ring );
92+
if ( n == 0 )
93+
{
94+
error->setObsolete();
95+
return;
96+
}
9297
const QgsPointV2 &p1 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + n ) % n ) );
9398
const QgsPointV2 &p2 = geometry->vertexAt( vidx );
9499
const QgsPointV2 &p3 = geometry->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + 1 ) % n ) );

‎src/plugins/geometry_checker/checks/qgsgeometryduplicatenodescheck.cpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ void QgsGeometryDuplicateNodesCheck::fixError( QgsGeometryCheckError *error, int
7373

7474
// Check if error still applies
7575
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
76+
if ( nVerts == 0 )
77+
{
78+
error->setObsolete();
79+
return;
80+
}
7681
QgsPointV2 pi = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex + nVerts - 1 ) % nVerts ) );
7782
QgsPointV2 pj = geom->vertexAt( error->vidx() );
7883
if ( QgsGeometryUtils::sqrDistance2D( pi, pj ) >= QgsGeometryCheckPrecision::tolerance() * QgsGeometryCheckPrecision::tolerance() )

‎src/plugins/geometry_checker/checks/qgsgeometrysegmentlengthcheck.cpp

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,12 @@ void QgsGeometrySegmentLengthCheck::fixError( QgsGeometryCheckError *error, int
7979

8080
// Check if error still applies
8181
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring );
82+
if ( nVerts == 0 )
83+
{
84+
error->setObsolete();
85+
return;
86+
}
87+
8288
QgsPointV2 pi = geom->vertexAt( error->vidx() );
8389
QgsPointV2 pj = geom->vertexAt( QgsVertexId( vidx.part, vidx.ring, ( vidx.vertex - 1 + nVerts ) % nVerts ) );
8490
double dist = qSqrt( QgsGeometryUtils::sqrDistance2D( pi, pj ) );

‎src/plugins/geometry_checker/checks/qgsgeometryselfintersectioncheck.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ void QgsGeometrySelfIntersectionCheck::fixError( QgsGeometryCheckError *error, i
110110
// Check if error still applies
111111
bool ringIsClosed = false;
112112
int nVerts = QgsGeometryCheckerUtils::polyLineSize( geom, vidx.part, vidx.ring, &ringIsClosed );
113-
if ( inter.segment1 >= nVerts || inter.segment2 >= nVerts )
113+
if ( nVerts == 0 || inter.segment1 >= nVerts || inter.segment2 >= nVerts )
114114
{
115115
error->setObsolete();
116116
return;

0 commit comments

Comments
 (0)
Please sign in to comment.