[postgis-tickets] r14882 - #3470, ST_Polygonize doesn't accept NULL geometries
Daniel Baston
dbaston at gmail.com
Tue May 3 17:56:52 PDT 2016
Author: dbaston
Date: 2016-05-03 17:56:52 -0700 (Tue, 03 May 2016)
New Revision: 14882
Modified:
trunk/postgis/lwgeom_accum.c
trunk/postgis/lwgeom_geos.c
trunk/regress/tickets.sql
trunk/regress/tickets_expected
Log:
#3470, ST_Polygonize doesn't accept NULL geometries
Modified: trunk/postgis/lwgeom_accum.c
===================================================================
--- trunk/postgis/lwgeom_accum.c 2016-05-04 00:34:37 UTC (rev 14881)
+++ trunk/postgis/lwgeom_accum.c 2016-05-04 00:56:52 UTC (rev 14882)
@@ -289,7 +289,9 @@
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);
}
Modified: trunk/postgis/lwgeom_geos.c
===================================================================
--- trunk/postgis/lwgeom_geos.c 2016-05-04 00:34:37 UTC (rev 14881)
+++ trunk/postgis/lwgeom_geos.c 2016-05-04 00:56:52 UTC (rev 14882)
@@ -3060,7 +3060,6 @@
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 @@
GEOSGeometry *geos_result;
const GEOSGeometry **vgeoms;
int srid=SRID_UNKNOWN;
- size_t offset;
#if POSTGIS_DEBUG_LEVEL >= 3
static int call=1;
#endif
@@ -3077,48 +3075,22 @@
call++;
#endif
- datum = PG_GETARG_DATUM(0);
+ if (PG_ARGISNULL(0))
+ PG_RETURN_NULL();
- /* Null array, null geometry (should be empty?) */
- if ( (Pointer *)datum == NULL ) PG_RETURN_NULL();
+ array = PG_GETARG_ARRAYTYPE_P(0);
+ nelems = array_nelems_not_null(array);
- array = DatumGetArrayTypeP(datum);
+ if (nelems == 0)
+ PG_RETURN_NULL();
- nelems = ArrayGetNItems(ARR_NDIM(array), ARR_DIMS(array));
+ POSTGIS_DEBUGF(3, "polygonize_garray: number of non-null elements: %d", nelems);
- POSTGIS_DEBUGF(3, "polygonize_garray: number of elements: %d", nelems);
-
- if ( nelems == 0 ) PG_RETURN_NULL();
-
/* 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);
+ vgeoms = (const GEOSGeometry**) ARRAY2GEOS(array, nelems, &is3d, &srid);
- 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));
- }
- }
-
POSTGIS_DEBUG(3, "polygonize_garray: invoking GEOSpolygonize");
geos_result = GEOSPolygonize(vgeoms, nelems);
@@ -3139,10 +3111,7 @@
PG_RETURN_NULL(); /*never get here */
}
- /*compressType(result); */
-
PG_RETURN_POINTER(result);
-
}
Modified: trunk/regress/tickets.sql
===================================================================
--- trunk/regress/tickets.sql 2016-05-04 00:34:37 UTC (rev 14881)
+++ trunk/regress/tickets.sql 2016-05-04 00:56:52 UTC (rev 14882)
@@ -962,5 +962,8 @@
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;
Modified: trunk/regress/tickets_expected
===================================================================
--- trunk/regress/tickets_expected 2016-05-04 00:34:37 UTC (rev 14881)
+++ trunk/regress/tickets_expected 2016-05-04 00:56:52 UTC (rev 14882)
@@ -292,3 +292,4 @@
#3437c|5
#3437d|5
#3437e|5
+#3470|t
More information about the postgis-tickets
mailing list