[geos-commits] r3445 - in branches/3.2: . source/operation/distance tests/unit/operation/distance

svn_geos at osgeo.org svn_geos at osgeo.org
Wed Jul 20 16:48:07 EDT 2011


Author: strk
Date: 2011-07-20 13:48:07 -0700 (Wed, 20 Jul 2011)
New Revision: 3445

Modified:
   branches/3.2/NEWS
   branches/3.2/source/operation/distance/DistanceOp.cpp
   branches/3.2/tests/unit/operation/distance/DistanceOpTest.cpp
Log:
Fix segfault in DistanceOp (#367)


Modified: branches/3.2/NEWS
===================================================================
--- branches/3.2/NEWS	2011-07-20 15:40:27 UTC (rev 3444)
+++ branches/3.2/NEWS	2011-07-20 20:48:07 UTC (rev 3445)
@@ -3,6 +3,7 @@
 
 - Bug fixes / improvements
   - ValidOp abort in presence of 2 touching holes forming an island (#449)
+  - DistanceOp segfaults on MULTIPOLYGON with EMPTY elements (#367)
 
 Changes in 3.2.2
  

Modified: branches/3.2/source/operation/distance/DistanceOp.cpp
===================================================================
--- branches/3.2/source/operation/distance/DistanceOp.cpp	2011-07-20 15:40:27 UTC (rev 3444)
+++ branches/3.2/source/operation/distance/DistanceOp.cpp	2011-07-20 20:48:07 UTC (rev 3445)
@@ -34,6 +34,7 @@
 #include <geos/geom/util/PolygonExtracter.h>
 #include <geos/geom/util/LinearComponentExtracter.h>
 #include <geos/geom/util/PointExtracter.h>
+#include <geos/util/IllegalArgumentException.h>
 
 #include <vector>
 #include <iostream>
@@ -138,6 +139,10 @@
 double
 DistanceOp::distance()
 {
+	if ( geom[0] == 0 || geom[1] == 0 )
+		throw geos::util::IllegalArgumentException("null geometries are not supported");
+	if ( geom[0]->isEmpty() || geom[1]->isEmpty() ) return minDistance;
+
 	computeMinDistance();
 	return minDistance;
 }

Modified: branches/3.2/tests/unit/operation/distance/DistanceOpTest.cpp
===================================================================
--- branches/3.2/tests/unit/operation/distance/DistanceOpTest.cpp	2011-07-20 15:40:27 UTC (rev 3444)
+++ branches/3.2/tests/unit/operation/distance/DistanceOpTest.cpp	2011-07-20 20:48:07 UTC (rev 3445)
@@ -455,6 +455,25 @@
 		// TODO: test closestPoints
 	}
 
+	// Test for bug #367
+	template<>
+	template<>
+	void object::test<19>()
+	{
+		using geos::operation::distance::DistanceOp;
+		using geos::geom::Coordinate;
+
+/// Or: MULTIPOLYGON((()))
+		std::string wkt0("MULTIPOLYGON((EMPTY))");
+		std::string wkt1("POINT(0 0)");
+
+		GeomPtr g0(wktreader.read(wkt0));
+		GeomPtr g1(wktreader.read(wkt1));
+
+		ensure_equals(DistanceOp::distance(*g0, *g1), DoubleMax);
+
+	}
+
 	// TODO: finish the tests by adding:
 	// 	LINESTRING - *all*
 	// 	MULTILINESTRING - *all*



More information about the geos-commits mailing list