From: Sandro Santilli Date: Tue, 14 Feb 2012 17:57:45 +0000 (+0000) Subject: Fix crash with empty polygons in P-I-P tests (#1578) X-Git-Tag: 2.0.0alpha5~7 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2936722b2a4f9a9afef89e513692e61a68c53769;p=postgis Fix crash with empty polygons in P-I-P tests (#1578) git-svn-id: http://svn.osgeo.org/postgis/trunk@9191 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/postgis/lwgeom_functions_analytic.c b/postgis/lwgeom_functions_analytic.c index 54d766388..3d4a2857a 100644 --- a/postgis/lwgeom_functions_analytic.c +++ b/postgis/lwgeom_functions_analytic.c @@ -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 */ diff --git a/regress/tickets.sql b/regress/tickets.sql index 615826466..ba3783d42 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -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; diff --git a/regress/tickets_expected b/regress/tickets_expected index 9b7c56774..e071f5e56 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -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