[geos-commits] [SCM] GEOS branch 3.8 updated. bc5429f45fc16a6c39dba2d4b9bcb841d70d01ee

git at osgeo.org git at osgeo.org
Tue Oct 13 12:32:27 PDT 2020


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, 3.8 has been updated
       via  bc5429f45fc16a6c39dba2d4b9bcb841d70d01ee (commit)
      from  d823c4014f7efcd8e5e68f38a4ad088507762045 (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 bc5429f45fc16a6c39dba2d4b9bcb841d70d01ee
Author: Sandro Santilli <strk at kbt.io>
Date:   Tue Oct 13 21:29:32 2020 +0200

    Surivive empty collection from GEOSInterpolate
    
    Fixes #1055 in 3.8 branch (3.8.2dev)

diff --git a/NEWS b/NEWS
index 9fc7353..f74067b 100644
--- a/NEWS
+++ b/NEWS
@@ -2,11 +2,13 @@ Changes in 3.8.2
 2020-xx-xx
 
 - Bug fixes / improvements
-  - DistanceOp against geometry with empty components 
+  - DistanceOp against geometry with empty components
     crashes (#1026, Paul Ramsey)
   - Remove undefined behaviour in CAPI (#1021, Greg Troxel)
   - WKT writing of MULTIPOINT with EMPTY component crash (#1027, Paul Ramsey)
   - Fix buffering problem (#1022, JTS-525, Paul Ramsey)
+  - Fix segfault in GEOSInterpolate against empty eollections (#1055,
+    Sandro Santilli)
 
 
 Changes in 3.8.1
diff --git a/src/linearref/LinearLocation.cpp b/src/linearref/LinearLocation.cpp
index ce93cb3..7d929cf 100644
--- a/src/linearref/LinearLocation.cpp
+++ b/src/linearref/LinearLocation.cpp
@@ -151,7 +151,14 @@ LinearLocation::getSegmentLength(const Geometry* linearGeom) const
 void
 LinearLocation::setToEnd(const Geometry* linear)
 {
-    componentIndex = linear->getNumGeometries() - 1;
+    componentIndex = linear->getNumGeometries();
+    if ( componentIndex == 0 )
+    {
+        segmentIndex = 0;
+        segmentFraction = 0;
+        return;
+    }
+    componentIndex--;
     const LineString* lastLine = dynamic_cast<const LineString*>(linear->getGeometryN(componentIndex));
     segmentIndex = lastLine->getNumPoints() - 1;
     segmentFraction = 1.0;
@@ -189,13 +196,13 @@ LinearLocation::isVertex() const
 Coordinate
 LinearLocation::getCoordinate(const Geometry* linearGeom) const
 {
+    if(linearGeom->isEmpty()) {
+        return Coordinate::getNull();
+    }
     const LineString* lineComp = dynamic_cast<const LineString*>(linearGeom->getGeometryN(componentIndex));
     if(! lineComp) {
         throw util::IllegalArgumentException("LinearLocation::getCoordinate only works with LineString geometries");
     }
-    if(linearGeom->isEmpty()) {
-        return Coordinate::getNull();
-    }
     Coordinate p0 = lineComp->getCoordinateN(segmentIndex);
     if(segmentIndex >= lineComp->getNumPoints() - 1) {
         return p0;
diff --git a/tests/unit/capi/GEOSInterpolateTest.cpp b/tests/unit/capi/GEOSInterpolateTest.cpp
index c51c905..b2d22ae 100644
--- a/tests/unit/capi/GEOSInterpolateTest.cpp
+++ b/tests/unit/capi/GEOSInterpolateTest.cpp
@@ -65,4 +65,16 @@ void object::test<1>
     ensure_equals(GEOSisEmpty(geom2), 1);
     GEOSGeom_destroy(geom2);
 }
+
+template<>
+template<>
+void object::test<2>
+()
+{
+    geom1_ = GEOSGeomFromWKT("GEOMETRYCOLLECTION EMPTY");
+    GEOSGeometry* geom2 = GEOSInterpolate(geom1_, 1);
+    ensure_equals(GEOSisEmpty(geom2), 1);
+    GEOSGeom_destroy(geom2);
+}
+
 } // namespace tut

-----------------------------------------------------------------------

Summary of changes:
 NEWS                                    |  4 +++-
 src/linearref/LinearLocation.cpp        | 15 +++++++++++----
 tests/unit/capi/GEOSInterpolateTest.cpp | 12 ++++++++++++
 3 files changed, 26 insertions(+), 5 deletions(-)


hooks/post-receive
-- 
GEOS


More information about the geos-commits mailing list