Skip to content
Permalink
Browse files

The wkb->geos conversion may fail for some reasons so it's necessary …

…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
wonder committed Jul 20, 2009
1 parent 99c50f2 commit 7e19431a371f0f410f983ae0610eef5a3e042889
Showing with 22 additions and 10 deletions.
  1. +22 −10 src/core/qgsgeometry.cpp
@@ -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;
}
}
@@ -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;
}
}
@@ -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 )
@@ -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 );

@@ -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 )
@@ -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
@@ -3917,6 +3922,7 @@ bool QgsGeometry::exportWkbToGeos()
mGeos = 0;
}

// this probably shouldn't return TRUE
if ( !mGeometry )
{
// no WKB => no GEOS
@@ -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
@@ -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
@@ -5062,7 +5070,8 @@ int QgsGeometry::mergeGeometriesMultiTypeSplit( QVector<GEOSGeometry*>& splitRes
{
if ( !mGeos || mDirtyGeos )
{
exportWkbToGeos();
if ( !exportWkbToGeos() )
return 1;
}

//convert mGeos to geometry collection
@@ -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

0 comments on commit 7e19431

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