From ef243988b01a829d21c5221b88b75a86d35ce008 Mon Sep 17 00:00:00 2001 From: Daniel Baston Date: Mon, 4 Sep 2017 00:37:56 +0000 Subject: [PATCH] #3578, Fix null return for ST_NumInteriorRings on empty polygon git-svn-id: http://svn.osgeo.org/postgis/trunk@15620 b70326c6-7e19-0410-871a-916f4a2858ee --- postgis/lwgeom_ogc.c | 25 +++++++++++++++++++------ regress/tickets.sql | 4 ++++ regress/tickets_expected | 2 ++ 3 files changed, 25 insertions(+), 6 deletions(-) diff --git a/postgis/lwgeom_ogc.c b/postgis/lwgeom_ogc.c index 5d909c5e9..b090d7fd1 100644 --- a/postgis/lwgeom_ogc.c +++ b/postgis/lwgeom_ogc.c @@ -413,19 +413,32 @@ Datum LWGEOM_numinteriorrings_polygon(PG_FUNCTION_ARGS) { GSERIALIZED *geom = PG_GETARG_GSERIALIZED_P(0); LWGEOM *lwgeom = lwgeom_from_gserialized(geom); - LWPOLY *poly = NULL; - LWCURVEPOLY *curvepoly = NULL; + int result = -1; if ( lwgeom->type == POLYGONTYPE ) { - poly = lwgeom_as_lwpoly(lwgeom); - result = poly->nrings - 1; + if (lwgeom_is_empty(lwgeom)) + { + result = 0; + } + else + { + const LWPOLY *poly = lwgeom_as_lwpoly(lwgeom); + result = poly->nrings - 1; + } } else if ( lwgeom->type == CURVEPOLYTYPE ) { - curvepoly = lwgeom_as_lwcurvepoly(lwgeom); - result = curvepoly->nrings - 1; + if (lwgeom_is_empty(lwgeom)) + { + result = 0; + } + else + { + const LWCURVEPOLY *curvepoly = lwgeom_as_lwcurvepoly(lwgeom); + result = curvepoly->nrings - 1; + } } lwgeom_free(lwgeom); diff --git a/regress/tickets.sql b/regress/tickets.sql index fab5d78d8..d774c4e71 100644 --- a/regress/tickets.sql +++ b/regress/tickets.sql @@ -980,6 +980,10 @@ WITH clustr AS ( SELECT '#3569', ST_CollectionHomogenize(geom)::box2d FROM clustr; +-- #3578 +SELECT '#3578a', ST_NumInteriorRings('POLYGON EMPTY'); +SELECT '#3578b', ST_NumInteriorRings('CURVEPOLYGON EMPTY'); + -- #3579 with params as ( diff --git a/regress/tickets_expected b/regress/tickets_expected index 452503060..86b62a664 100644 --- a/regress/tickets_expected +++ b/regress/tickets_expected @@ -296,6 +296,8 @@ ERROR: invalid KML representation #3470|t #3470b|50 #3569|BOX(1 2,3 4) +#3578a|0 +#3578b|0 #3579|f|t #3620a|POINT(3 7) #3620b|POINT(2 8) -- 2.50.0