]> granicus.if.org Git - postgis/commitdiff
#3470, ST_Polygonize doesn't accept NULL geometries
authorDaniel Baston <dbaston@gmail.com>
Wed, 4 May 2016 00:56:52 +0000 (00:56 +0000)
committerDaniel Baston <dbaston@gmail.com>
Wed, 4 May 2016 00:56:52 +0000 (00:56 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@14882 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_accum.c
postgis/lwgeom_geos.c
regress/tickets.sql
regress/tickets_expected

index 3eb5a98b6238cc6f758287b9fd6a2015bc26f8c8..951c51a5941cba2994dbe362ecc1bdd9a674a19b 100644 (file)
@@ -289,7 +289,9 @@ pgis_geometry_polygonize_finalfn(PG_FUNCTION_ARGS)
        p = (pgis_abs*) PG_GETARG_POINTER(0);
 
        geometry_array = pgis_accum_finalfn(p, CurrentMemoryContext, fcinfo);
-       result = DirectFunctionCall1( polygonize_garray, geometry_array );
+       result = PGISDirectFunctionCall1( polygonize_garray, geometry_array );
+       if (!result)
+               PG_RETURN_NULL();
 
        PG_RETURN_DATUM(result);
 }
index a87fda92326bfb479880d01f7c147dc9b85c5d52..8018cc926babdfba9239acef27c5003405924520 100644 (file)
@@ -3060,7 +3060,6 @@ Datum GEOSnoop(PG_FUNCTION_ARGS)
 PG_FUNCTION_INFO_V1(polygonize_garray);
 Datum polygonize_garray(PG_FUNCTION_ARGS)
 {
-       Datum datum;
        ArrayType *array;
        int is3d = 0;
        uint32 nelems, i;
@@ -3068,7 +3067,6 @@ Datum polygonize_garray(PG_FUNCTION_ARGS)
        GEOSGeometry *geos_result;
        const GEOSGeometry **vgeoms;
        int srid=SRID_UNKNOWN;
-       size_t offset;
 #if POSTGIS_DEBUG_LEVEL >= 3
        static int call=1;
 #endif
@@ -3077,47 +3075,21 @@ Datum polygonize_garray(PG_FUNCTION_ARGS)
        call++;
 #endif
 
-       datum = PG_GETARG_DATUM(0);
-
-       /* Null array, null geometry (should be empty?) */
-       if ( (Pointer *)datum == NULL ) PG_RETURN_NULL();
-
-       array = DatumGetArrayTypeP(datum);
+       if (PG_ARGISNULL(0))
+               PG_RETURN_NULL();
 
-       nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
+       array = PG_GETARG_ARRAYTYPE_P(0);
+       nelems = array_nelems_not_null(array);
 
-       POSTGIS_DEBUGF(3, "polygonize_garray: number of elements: %d", nelems);
+       if (nelems == 0)
+               PG_RETURN_NULL();
 
-       if ( nelems == 0 ) PG_RETURN_NULL();
+       POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
 
        /* Ok, we really need geos now ;) */
        initGEOS(lwpgnotice, lwgeom_geos_error);
 
-       vgeoms = palloc(sizeof(GEOSGeometry *)*nelems);
-       offset = 0;
-       for (i=0; i<nelems; i++)
-       {
-               GEOSGeometry* g;
-               GSERIALIZED *geom = (GSERIALIZED *)(ARR_DATA_PTR(array)+offset);
-               offset += INTALIGN(VARSIZE(geom));
-               if ( ! is3d ) is3d = gserialized_has_z(geom);
-
-               g = (GEOSGeometry *)POSTGIS2GEOS(geom);
-               if ( 0 == g )   /* exception thrown at construction */
-               {
-                       HANDLE_GEOS_ERROR("Geometry could not be converted to GEOS");
-                       PG_RETURN_NULL();
-               }
-               vgeoms[i] = g;
-               if ( ! i )
-               {
-                       srid = gserialized_get_srid(geom);
-               }
-               else
-               {
-                       error_if_srid_mismatch(srid, gserialized_get_srid(geom));
-               }
-       }
+       vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
 
        POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
 
@@ -3139,10 +3111,7 @@ Datum polygonize_garray(PG_FUNCTION_ARGS)
                PG_RETURN_NULL(); /*never get here */
        }
 
-       /*compressType(result); */
-
        PG_RETURN_POINTER(result);
-
 }
 
 
index eeae6a3ab0946e15b795e16e96fb5092f134d6b3..2008aa8c8f80b7883a302e2261b1ac542e59bd77 100644 (file)
@@ -962,5 +962,8 @@ SELECT '#3437d' AS t, count(*) FROM mp INNER JOIN p ON ST_Covers(mp.geom, p.geom
 UNION ALL
 SELECT '#3437e' AS t, count(*) FROM mp INNER JOIN p ON ST_Within(p.geom, mp.geom);
 
+-- #3470
+SELECT '#3470', ST_Polygonize(ARRAY[NULL]::geometry[]) IS NULL;
+
 -- Clean up
 DELETE FROM spatial_ref_sys;
index 03247250f46509e826b7cd47b98e66d2da931cdd..6530b78a601d0870d33a523a8f961624884008e7 100644 (file)
@@ -292,3 +292,4 @@ ERROR:  invalid KML representation
 #3437c|5
 #3437d|5
 #3437e|5
+#3470|t