]> granicus.if.org Git - postgis/commitdiff
Fixed short-allocation in lwcollection_clone()
authorSandro Santilli <strk@keybit.net>
Thu, 1 Dec 2005 13:46:19 +0000 (13:46 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 1 Dec 2005 13:46:19 +0000 (13:46 +0000)
git-svn-id: http://svn.osgeo.org/postgis/branches/pgis_1_0@2112 b70326c6-7e19-0410-871a-916f4a2858ee

CHANGES
lwgeom/lwcollection.c

diff --git a/CHANGES b/CHANGES
index 24b2f2884c478f05711d4b206a3f3cd698b6e935..22c70169e4ac5d439e65fa747621b9f73682a8a3 100644 (file)
--- 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
index ce8c4344bfa2e5b3cd9165bef8365891b2094830..5807b10495b8fb3b986117d5bd98e19a5460a1b0 100644 (file)
@@ -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; i<g->ngeoms; i++)
+       if ( g->ngeoms > 0 )
        {
-               ret->geoms[i] = lwgeom_clone(g->geoms[i]);
+               ret->geoms = lwalloc(sizeof(LWGEOM *)*g->ngeoms);
+               for (i=0; i<g->ngeoms; 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;
 }