Skip to content

Commit

Permalink
Fix crash in QgsGeometry::unaryUnion with empty geometries
Browse files Browse the repository at this point in the history
  • Loading branch information
nyalldawson committed Jul 13, 2016
1 parent 2db7fca commit b61641d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core/geometry/qgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1618,7 +1618,7 @@ QgsGeometry *QgsGeometry::unaryUnion( const QList<QgsGeometry*> &geometryList )
QList<QgsGeometry*>::const_iterator it = geometryList.constBegin();
for ( ; it != geometryList.constEnd(); ++it )
{
if ( *it )
if ( *it && !(( *it )->isEmpty() ) )
{
geomV2List.append(( *it )->geometry() );
}
Expand Down
16 changes: 16 additions & 0 deletions tests/src/core/testqgsgeometry.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ class TestQgsGeometry : public QObject
void bufferCheck();
void smoothCheck();

void unaryUnion();

void dataStream();

void exportToGeoJSON();
Expand Down Expand Up @@ -3256,6 +3258,20 @@ void TestQgsGeometry::smoothCheck()
QVERIFY( QgsGeometry::compare( multipoly, expectedMultiPoly ) );
}

void TestQgsGeometry::unaryUnion()
{
//test QgsGeometry::unaryUnion with null geometry
QString wkt1 = "Polygon ((0 0, 10 0, 10 10, 0 10, 0 0 ))";
QString wkt2 = "Polygon ((2 2, 4 2, 4 4, 2 4, 2 2))";
QScopedPointer< QgsGeometry > geom1( QgsGeometry::fromWkt( wkt1 ) );
QScopedPointer< QgsGeometry > geom2( QgsGeometry::fromWkt( wkt2 ) );
QScopedPointer< QgsGeometry > empty( new QgsGeometry() );
QList< QgsGeometry* > list;
list << geom1.data() << empty.data() << geom2.data();

QScopedPointer< QgsGeometry > result( QgsGeometry::unaryUnion( list ) );
}

void TestQgsGeometry::dataStream()
{
QString wkt = "Point (40 50)";
Expand Down

0 comments on commit b61641d

Please sign in to comment.