Skip to content

Commit

Permalink
The wkb->geos conversion may fail for some reasons so it's necessary …
Browse files Browse the repository at this point in the history
…to check the result of it.

This avoids some possible segfaults with invalid geometries.
Contributed by Vita Cizek.


git-svn-id: http://svn.osgeo.org/qgis/trunk/qgis@11116 c8812cc2-4d05-0410-92ff-de0c093fc19c
  • Loading branch information
wonder committed Jul 20, 2009
1 parent 99c50f2 commit 7e19431
Showing 1 changed file with 22 additions and 10 deletions.
32 changes: 22 additions & 10 deletions src/core/qgsgeometry.cpp
Expand Up @@ -259,8 +259,8 @@ static GEOSCoordSequence *createGeosCoordSequence( const QgsPolyline& points )
catch ( GEOSException &e )
{
Q_UNUSED( e );
if ( coord )
GEOSCoordSeq_destroy( coord );
/*if ( coord )
GEOSCoordSeq_destroy( coord );*/
throw;
}
}
Expand Down Expand Up @@ -335,8 +335,9 @@ static GEOSGeometry *createGeosLinearRing( const QgsPolyline& polyline )
catch ( GEOSException &e )
{
Q_UNUSED( e );
/* as MH has noticed ^, this crashes geos
if ( coord )
GEOSCoordSeq_destroy( coord );
GEOSCoordSeq_destroy( coord );*/
return 0;
}
}
Expand Down Expand Up @@ -2349,7 +2350,8 @@ double QgsGeometry::closestVertexWithContext( const QgsPoint& point, int& atVert
int closestVertexIndex = 0;

// set up the GEOS geometry
exportWkbToGeos();
if ( !exportWkbToGeos() )
return -1;

const GEOSGeometry *g = GEOSGetExteriorRing( mGeos );
if ( g == NULL )
Expand Down Expand Up @@ -2628,7 +2630,8 @@ int QgsGeometry::addRing( const QList<QgsPoint>& ring )

//create geos geometry from wkb if not already there
if ( !mGeos || mDirtyGeos )
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 6;

int type = GEOSGeomTypeId( mGeos );

Expand Down Expand Up @@ -2831,7 +2834,8 @@ int QgsGeometry::addIsland( const QList<QgsPoint>& ring )
//create geos geometry from wkb if not already there
if ( !mGeos || mDirtyGeos )
{
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 4;
}

if ( GEOSGeomTypeId( mGeos ) != GEOS_MULTIPOLYGON )
Expand Down Expand Up @@ -3164,7 +3168,8 @@ int QgsGeometry::splitGeometry( const QList<QgsPoint>& splitLine, QList<QgsGeome
}
if ( !mGeos || mDirtyGeos )
{
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 1;
}

//make sure splitLine is valid
Expand Down Expand Up @@ -3917,6 +3922,7 @@ bool QgsGeometry::exportWkbToGeos()
mGeos = 0;
}

// this probably shouldn't return TRUE
if ( !mGeometry )
{
// no WKB => no GEOS
Expand Down Expand Up @@ -4768,7 +4774,8 @@ int QgsGeometry::splitLinearGeometry( GEOSGeometry *splitLine, QList<QgsGeometry

if ( !mGeos || mDirtyGeos )
{
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 5;
}

//first test if linestring intersects geometry. If not, return straight away
Expand Down Expand Up @@ -4844,7 +4851,8 @@ int QgsGeometry::splitPolygonGeometry( GEOSGeometry* splitLine, QList<QgsGeometr

if ( !mGeos || mDirtyGeos )
{
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 5;
}

//first test if linestring intersects geometry. If not, return straight away
Expand Down Expand Up @@ -5062,7 +5070,8 @@ int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitRes
{
if ( !mGeos || mDirtyGeos )
{
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 1;
}

//convert mGeos to geometry collection
Expand Down Expand Up @@ -5328,6 +5337,9 @@ double QgsGeometry::distance( QgsGeometry& geom )
geom.exportWkbToGeos();
}

if ( mGeos == NULL || geom.mGeos == NULL)
return -1.0;

double dist = -1.0;

try
Expand Down

0 comments on commit 7e19431

Please sign in to comment.