[QGIS Commit] r11116 - trunk/qgis/src/core

svn_qgis at osgeo.org svn_qgis at osgeo.org
Mon Jul 20 11:02:53 EDT 2009


Author: wonder
Date: 2009-07-20 11:02:50 -0400 (Mon, 20 Jul 2009)
New Revision: 11116

Modified:
   trunk/qgis/src/core/qgsgeometry.cpp
Log:
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.


Modified: trunk/qgis/src/core/qgsgeometry.cpp
===================================================================
--- trunk/qgis/src/core/qgsgeometry.cpp	2009-07-20 14:53:15 UTC (rev 11115)
+++ trunk/qgis/src/core/qgsgeometry.cpp	2009-07-20 15:02:50 UTC (rev 11116)
@@ -259,8 +259,8 @@
   catch ( GEOSException &e )
   {
     Q_UNUSED( e );
-    if ( coord )
-      GEOSCoordSeq_destroy( coord );
+    /*if ( coord )
+      GEOSCoordSeq_destroy( coord );*/
     throw;
   }
 }
@@ -335,8 +335,9 @@
   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 @@
     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 @@
 
   //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 @@
   //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 @@
   }
   if ( !mGeos || mDirtyGeos )
   {
-    exportWkbToGeos();
+    if ( !exportWkbToGeos() )
+      return 1;
   }
 
   //make sure splitLine is valid
@@ -3917,6 +3922,7 @@
     mGeos = 0;
   }
 
+  // this probably shouldn't return TRUE
   if ( !mGeometry )
   {
     // no WKB => no GEOS
@@ -4768,7 +4774,8 @@
 
   if ( !mGeos || mDirtyGeos )
   {
-    exportWkbToGeos();
+    if ( !exportWkbToGeos() )
+      return 5;
   }
 
   //first test if linestring intersects geometry. If not, return straight away
@@ -4844,7 +4851,8 @@
 
   if ( !mGeos || mDirtyGeos )
   {
-    exportWkbToGeos();
+    if ( !exportWkbToGeos() )
+      return 5;
   }
 
   //first test if linestring intersects geometry. If not, return straight away
@@ -5062,7 +5070,8 @@
 {
   if ( !mGeos || mDirtyGeos )
   {
-    exportWkbToGeos();
+    if ( !exportWkbToGeos() )
+      return 1;
   }
 
   //convert mGeos to geometry collection
@@ -5328,6 +5337,9 @@
     geom.exportWkbToGeos();
   }
 
+  if ( mGeos == NULL || geom.mGeos == NULL)
+    return -1.0;
+
   double dist = -1.0;
 
   try



More information about the QGIS-commit mailing list