]> granicus.if.org Git - postgis/commitdiff
Fix crash with empty polygons in P-I-P tests (#1578)
authorSandro Santilli <strk@keybit.net>
Tue, 14 Feb 2012 17:57:45 +0000 (17:57 +0000)
committerSandro Santilli <strk@keybit.net>
Tue, 14 Feb 2012 17:57:45 +0000 (17:57 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9191 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_functions_analytic.c
regress/tickets.sql
regress/tickets_expected

index 54d76638893001b4bfb4ff84c67ed9bef6eac279..3d4a2857a3fbb8d3882a26ff452b6266cd28a6b8 100644 (file)
@@ -1175,6 +1175,9 @@ int point_in_polygon(LWPOLY *polygon, LWPOINT *point)
        getPoint2d_p(point->point, 0, &pt);
        /* assume bbox short-circuit has already been attempted */
 
+       /* everything is outside of an empty polygon */
+       if ( polygon->nrings == 0 ) return -1;
+
        ring = polygon->rings[0];
        in_ring = point_in_ring(polygon->rings[0], &pt);
        if ( in_ring == -1) /* outside the exterior ring */
@@ -1224,6 +1227,10 @@ int point_in_multipolygon(LWMPOLY *mpolygon, LWPOINT *point)
        {
 
                LWPOLY *polygon = mpolygon->geoms[j];
+
+               /* everything is outside of an empty polygon */
+               if ( polygon->nrings == 0 ) continue;
+
                ring = polygon->rings[0];
                in_ring = point_in_ring(polygon->rings[0], &pt);
                if ( in_ring == -1) /* outside the exterior ring */
index 615826466de40b130e8cebe7ab08377f24bcf492..ba3783d42e5a084e4d66b568eb1346d6f6fdda64 100644 (file)
@@ -596,6 +596,13 @@ with inp as ( select
 ::geometry as g )
 select '#1543', st_astext(g), st_astext(st_buildarea(g)) from inp;
 
+-- #1578
+with inp as (
+ select ST_Collect('POLYGON EMPTY', 'POLYGON EMPTY') as mp,
+        'POINT(0 0)'::geometry as p
+)
+select '#1578', _st_within(p, mp), _st_intersects(p, mp) FROM inp;
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
 
index 9b7c567742911b47d8fbaf7a0a98c315b19a0a97..e071f5e566eaed76567a98f00304d56451244495 100644 (file)
@@ -197,3 +197,4 @@ ERROR:  AddToPROJ4SRSCache: couldn't parse proj4 string: '': (null)
 #1398a|POINT(-119.093153 45.632669)
 #1398b|POINT(-160.137654 77.091608)
 #1543|MULTILINESTRING((0 0,10 0,10 10,0 0),(0 0))|POLYGON((0 0,10 10,10 0,0 0))
+#1578|f|f