[geos-commits] r2187 - in trunk: source/geom/prep
tests/unit/geom/prep
svn_geos at osgeo.org
svn_geos at osgeo.org
Tue Sep 16 16:58:49 EDT 2008
Author: mloskot
Date: 2008-09-16 16:58:49 -0400 (Tue, 16 Sep 2008)
New Revision: 2187
Modified:
trunk/source/geom/prep/PreparedGeometryFactory.cpp
trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
Log:
Fixed crash of Prepared Geometry construction with nullptr to Geometry object (Ticket #197).
Modified: trunk/source/geom/prep/PreparedGeometryFactory.cpp
===================================================================
--- trunk/source/geom/prep/PreparedGeometryFactory.cpp 2008-09-16 20:55:42 UTC (rev 2186)
+++ trunk/source/geom/prep/PreparedGeometryFactory.cpp 2008-09-16 20:58:49 UTC (rev 2187)
@@ -21,13 +21,13 @@
#include <geos/geom/MultiLineString.h>
#include <geos/geom/Polygon.h>
#include <geos/geom/MultiPolygon.h>
-
#include <geos/geom/prep/PreparedGeometryFactory.h>
#include <geos/geom/prep/PreparedGeometry.h>
#include <geos/geom/prep/BasicPreparedGeometry.h>
#include <geos/geom/prep/PreparedPolygon.h>
#include <geos/geom/prep/PreparedLineString.h>
#include <geos/geom/prep/PreparedPoint.h>
+#include <geos/util/IllegalArgumentException.h>
namespace geos {
namespace geom { // geos.geom
@@ -38,6 +38,11 @@
{
using geos::geom::GeometryTypeId;
+ if (0 == g)
+ {
+ throw util::IllegalArgumentException("PreparedGeometry constructd with null Geometry object");
+ }
+
PreparedGeometry* pg = 0;
switch ( g->getGeometryTypeId() )
Modified: trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp
===================================================================
--- trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp 2008-09-16 20:55:42 UTC (rev 2186)
+++ trunk/tests/unit/geom/prep/PreparedGeometryFactoryTest.cpp 2008-09-16 20:58:49 UTC (rev 2187)
@@ -75,8 +75,20 @@
template<>
void object::test<2>()
{
- // FIXME - mloskot: null pointer throws segfault (Ticket #197)
- // ensure(0 == prep::PreparedGeometryFactory::prepare(0));
+ try
+ {
+ GeometryPtr nullgeom = 0; // intentionally nullptr
+ prep::PreparedGeometry const* pg = 0;
+
+ pg = prep::PreparedGeometryFactory::prepare(nullgeom);
+
+ fail("IllegalArgumentException expected");
+ }
+ catch (geos::util::IllegalArgumentException const& e)
+ {
+ const char* msg = e.what(); // ok
+ ensure( msg != 0 );
+ }
}
// Test passing null-pointer to create method
@@ -84,11 +96,22 @@
template<>
void object::test<3>()
{
- prep::PreparedGeometryFactory pgf;
- UNREFERENCED_PARAMETER(pgf);
-
- // FIXME - mloskot: null pointer throws segfault (Ticket #197)
- // ensure(0 == pgf.create(0));
+ try
+ {
+ GeometryPtr nullgeom = 0; // intentionally nullptr
+ prep::PreparedGeometry const* pg = 0;
+
+ prep::PreparedGeometryFactory pgf;
+
+ pg = pgf.create(nullgeom);
+
+ fail("IllegalArgumentException expected");
+ }
+ catch (geos::util::IllegalArgumentException const& e)
+ {
+ const char* msg = e.what(); // ok
+ ensure( msg != 0 );
+ }
}
// Test prepare empty GEOMETRY
More information about the geos-commits
mailing list