From: Paul Ramsey Date: Fri, 21 Aug 2015 13:37:55 +0000 (+0000) Subject: #3254, ST_SubDivide garden crash, not empty safe X-Git-Tag: 2.2.0rc1~122 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=784a57f2d8076fdea00c562202a8157d78169f73;p=postgis #3254, ST_SubDivide garden crash, not empty safe git-svn-id: http://svn.osgeo.org/postgis/trunk@13969 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/lwgeom.c b/liblwgeom/lwgeom.c index 04812494a..f07b4ac15 100644 --- a/liblwgeom/lwgeom.c +++ b/liblwgeom/lwgeom.c @@ -1995,14 +1995,20 @@ lwgeom_subdivide(const LWGEOM *geom, int maxvertices) static int startdepth = 0; static int minmaxvertices = 8; LWCOLLECTION *col; - GBOX clip = *(lwgeom_get_bbox(geom)); + GBOX clip; + + col = lwcollection_construct_empty(COLLECTIONTYPE, geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom)); + + if ( lwgeom_is_empty(geom) ) + return col; if ( maxvertices < minmaxvertices ) { + lwcollection_free(col); lwerror("%s: cannot subdivide to fewer than %d vertices per output", __func__, minmaxvertices); } - - col = lwcollection_construct_empty(COLLECTIONTYPE, geom->srid, lwgeom_has_z(geom), lwgeom_has_m(geom)); + + clip = *(lwgeom_get_bbox(geom)); lwgeom_subdivide_recursive(geom, maxvertices, startdepth, col, &clip); lwgeom_set_srid((LWGEOM*)col, geom->srid); return col;