[geos-commits] [SCM] GEOS branch main updated. 80398b0377f9597f6c9b05b1684e00d97f04ebef
git at osgeo.org
git at osgeo.org
Mon Oct 4 13:29:51 PDT 2021
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "GEOS".
The branch, main has been updated
via 80398b0377f9597f6c9b05b1684e00d97f04ebef (commit)
from f24c181ec306d8f92429d553a316653e2760e2d4 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 80398b0377f9597f6c9b05b1684e00d97f04ebef
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Mon Oct 4 13:14:01 2021 -0700
Protect IsValidOp from null inputs
diff --git a/src/operation/valid/IsValidOp.cpp b/src/operation/valid/IsValidOp.cpp
index 5f27fbb..a54dc14 100644
--- a/src/operation/valid/IsValidOp.cpp
+++ b/src/operation/valid/IsValidOp.cpp
@@ -28,6 +28,7 @@
#include <geos/operation/valid/IndexedNestedHoleTester.h>
#include <geos/operation/valid/IndexedNestedPolygonTester.h>
#include <geos/util/UnsupportedOperationException.h>
+#include <geos/util/IllegalArgumentException.h>
#include <cmath>
@@ -80,9 +81,11 @@ IsValidOp::logInvalid(int code, const Coordinate* pt)
bool
IsValidOp::isValidGeometry(const Geometry* g)
{
- assert(g);
validErr.reset(nullptr);
+ if (!g)
+ throw util::IllegalArgumentException("Null geometry argument to IsValidOp");
+
// empty geometries are always valid
if (g->isEmpty()) return true;
switch (g->getGeometryTypeId()) {
diff --git a/tests/unit/capi/GEOSisValidTest.cpp b/tests/unit/capi/GEOSisValidTest.cpp
index 86dcac5..a99684b 100644
--- a/tests/unit/capi/GEOSisValidTest.cpp
+++ b/tests/unit/capi/GEOSisValidTest.cpp
@@ -50,13 +50,18 @@ void object::test<3>()
GEOSCoordSeq_setXY(shell_seq, i, shell_coords[2*i], shell_coords[2*i+1]);
}
+ // Unclosed ring fails in construction
+ // Linear ring takes ownership of coordinate sequence and
+ // frees it when construction fails
GEOSGeometry* shell = GEOSGeom_createLinearRing(shell_seq);
ensure(shell == nullptr);
+ // So we end up handing nullptr into create polygon
GEOSGeometry* polygon = GEOSGeom_createPolygon(shell, nullptr, 0);
ensure(polygon == nullptr);
- // char isvalid = GEOSisValid(polygon);
- // ensure_equals(0, isvalid);
- // GEOSGeom_destroy(polygon);
+ // Which also returns nullptr and that goes into isvalid
+ char isvalid = GEOSisValid(polygon);
+ // Which causes an exception that we catch
+ ensure_equals(2, isvalid);
}
} // namespace tut
-----------------------------------------------------------------------
Summary of changes:
src/operation/valid/IsValidOp.cpp | 5 ++++-
tests/unit/capi/GEOSisValidTest.cpp | 11 ++++++++---
2 files changed, 12 insertions(+), 4 deletions(-)
hooks/post-receive
--
GEOS
More information about the geos-commits
mailing list