Skip to content

Commit

Permalink
Fix crash in QgsGeometry::splitGeometry
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Oct 18, 2017
1 parent a6ac876 commit f77377e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 10 deletions.
14 changes: 4 additions & 10 deletions src/core/geometry/qgsgeos.cpp
Expand Up @@ -888,25 +888,19 @@ QgsGeometryEngine::EngineOperationResult QgsGeos::splitPolygonGeometry( GEOSGeom
}
GEOSGeom_destroy_r( geosinit.ctxt, polygons );

bool splitDone = true;
int nGeometriesThis = numberOfGeometries( mGeos ); //original number of geometries
if ( testedGeometries.size() == nGeometriesThis )
{
splitDone = false;
}

mergeGeometriesMultiTypeSplit( testedGeometries );

//no split done, preserve original geometry
if ( !splitDone )
if ( testedGeometries.empty() || testedGeometries.size() == nGeometriesThis )
{
//no split done, preserve original geometry
for ( int i = 0; i < testedGeometries.size(); ++i )
{
GEOSGeom_destroy_r( geosinit.ctxt, testedGeometries[i] );
}
return NothingHappened;
}

mergeGeometriesMultiTypeSplit( testedGeometries );

int i;
for ( i = 0; i < testedGeometries.size() && GEOSisValid_r( geosinit.ctxt, testedGeometries[i] ); ++i )
;
Expand Down
11 changes: 11 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Expand Up @@ -136,6 +136,7 @@ class TestQgsGeometry : public QObject
void createCollectionOfType();

void minimalEnclosingCircle( );
void splitGeometry();

private:
//! A helper method to do a render check to see if the geometry op is as expected
Expand Down Expand Up @@ -15553,6 +15554,16 @@ void TestQgsGeometry::minimalEnclosingCircle()

}

void TestQgsGeometry::splitGeometry()
{
QgsGeometry g1 = QgsGeometry::fromWkt( QStringLiteral( "Polygon ((492980.38648063864093274 7082334.45244149677455425, 493082.65415841294452548 7082319.87918917648494244, 492980.38648063858272508 7082334.45244149677455425, 492980.38648063864093274 7082334.45244149677455425))" ) );
QList<QgsGeometry> newGeoms;
QList<QgsPointXY> testPoints;
QCOMPARE( g1.splitGeometry( QList< QgsPointXY >() << QgsPointXY( 493825.46541286131832749, 7082214.02779923938214779 ) << QgsPointXY( 492955.04876351181883365, 7082338.06309300474822521 ),
newGeoms, false, testPoints ), QgsGeometry::NothingHappened );
QVERIFY( newGeoms.isEmpty() );
}


QGSTEST_MAIN( TestQgsGeometry )
#include "testqgsgeometry.moc"

0 comments on commit f77377e

Please sign in to comment.