From 77e43a5db6808c1cf5639531d4ea7242f9a3034b Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 1 Dec 2005 13:46:19 +0000 Subject: [PATCH] Fixed short-allocation in lwcollection_clone() git-svn-id: http://svn.osgeo.org/postgis/branches/pgis_1_0@2112 b70326c6-7e19-0410-871a-916f4a2858ee --- CHANGES | 1 + lwgeom/lwcollection.c | 20 ++++++++++++++++---- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 24b2f2884..22c70169e 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,7 @@ PostGIS 1.0.6CVS - Fixed geom_accum(NULL, NULL) segfault - Initial support for postgresql 8.2 - Fixed segfault in addPoint() + - Fixed short-allocation in lwcollection_clone() PostGIS 1.0.5 2005/11/25 diff --git a/lwgeom/lwcollection.c b/lwgeom/lwcollection.c index ce8c4344b..5807b1049 100644 --- a/lwgeom/lwcollection.c +++ b/lwgeom/lwcollection.c @@ -220,18 +220,30 @@ lwcollection_compute_box2d_p(LWCOLLECTION *col, BOX2DFLOAT4 *box) return 1; } -// Clone LWCOLLECTION object. POINTARRAY are not copied. +/* + * Clone LWCOLLECTION object. POINTARRAY are not copied. + * Bbox is cloned if present in input. + */ LWCOLLECTION * lwcollection_clone(const LWCOLLECTION *g) { uint32 i; LWCOLLECTION *ret = lwalloc(sizeof(LWCOLLECTION)); memcpy(ret, g, sizeof(LWCOLLECTION)); - for (i=0; ingeoms; i++) + if ( g->ngeoms > 0 ) { - ret->geoms[i] = lwgeom_clone(g->geoms[i]); + ret->geoms = lwalloc(sizeof(LWGEOM *)*g->ngeoms); + for (i=0; ingeoms; i++) + { + ret->geoms[i] = lwgeom_clone(g->geoms[i]); + } + if ( g->bbox ) ret->bbox = box2d_clone(g->bbox); + } + else + { + ret->bbox = NULL; // empty collection + ret->geoms = NULL; } - if ( g->bbox ) ret->bbox = box2d_clone(g->bbox); return ret; } -- 2.40.0