]> granicus.if.org Git - postgis/commitdiff
#3578, Fix null return for ST_NumInteriorRings on empty polygon
authorDaniel Baston <dbaston@gmail.com>
Mon, 4 Sep 2017 00:37:56 +0000 (00:37 +0000)
committerDaniel Baston <dbaston@gmail.com>
Mon, 4 Sep 2017 00:37:56 +0000 (00:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15620 b70326c6-7e19-0410-871a-916f4a2858ee

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

index 5d909c5e9dfdbb5655b0f59a348810d1ff4d68ff..b090d7fd10fddbc5014718270fc3efe93cf3332e 100644 (file)
@@ -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);
index fab5d78d8aed8b391313faedc1181e4f009dbd93..d774c4e7185f4b174e99e4f0ae109fe792240812 100644 (file)
@@ -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 (
index 4525030603cde8449466af1256f542989507febd..86b62a6642c1d452e74df563cd9e61bf9155b1c7 100644 (file)
@@ -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)