]> granicus.if.org Git - postgis/commitdiff
Fix #179: ST_MakeLine and ST_MakeLine_Garry crash server with null arrays again....
authorMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Wed, 7 Oct 2009 12:16:04 +0000 (12:16 +0000)
committerMark Cave-Ayland <mark.cave-ayland@siriusit.co.uk>
Wed, 7 Oct 2009 12:16:04 +0000 (12:16 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@4618 b70326c6-7e19-0410-871a-916f4a2858ee

postgis/lwgeom_accum.c
postgis/lwgeom_functions_basic.c

index 05e97d85737cd474f20fa8d05fb3f38c9ed90698..cc4ac34dc65c45994a0ad6b9e95c33ad9fd686f7 100644 (file)
@@ -284,7 +284,9 @@ pgis_geometry_makeline_finalfn(PG_FUNCTION_ARGS)
        p = (pgis_abs*) PG_GETARG_POINTER(0);
 
        geometry_array = pgis_accum_finalfn(p, CurrentMemoryContext, fcinfo);
-       result = DirectFunctionCall1( LWGEOM_makeline_garray, geometry_array );
+       result = PGISDirectFunctionCall1( LWGEOM_makeline_garray, geometry_array );
+       if (!result)
+               PG_RETURN_NULL();
 
        PG_RETURN_DATUM(result);
 }
index 3fd59f6ec8901f82b33721adfbea8c32d5301b90..129790fd900d6ec7a7107ca0707df845b0310f59 100644 (file)
@@ -2156,6 +2156,9 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
        size_t offset;
        int SRID=-1;
 
+       bits8 *bitmap;
+       int bitmask;
+
        POSTGIS_DEBUG(2, "LWGEOM_makeline_garray called.");
 
        /* Get input datum */
@@ -2195,34 +2198,51 @@ Datum LWGEOM_makeline_garray(PG_FUNCTION_ARGS)
        lwpoints = palloc(sizeof(LWGEOM *)*nelems);
        npoints = 0;
        offset = 0;
+       bitmap = ARR_NULLBITMAP(array);
+       bitmask = 1;
        for (i=0; i<nelems; i++)
        {
-               PG_LWGEOM *geom = (PG_LWGEOM *)(ARR_DATA_PTR(array)+offset);
-               offset += INTALIGN(VARSIZE(geom));
-
-               if ( TYPE_GETTYPE(geom->type) != POINTTYPE ) continue;
-
-               lwpoints[npoints++] =
-                   lwpoint_deserialize(SERIALIZED_FORM(geom));
-
-               /* Check SRID homogeneity */
-               if ( npoints == 1 )
-               {
-                       /* Get first geometry SRID */
-                       SRID = lwpoints[npoints-1]->SRID;
+               /* Don't do anything for NULL values */  
+               if ((bitmap && (*bitmap & bitmask) != 0) || !bitmap) 
+               { 
+                       PG_LWGEOM *geom = (PG_LWGEOM *)(ARR_DATA_PTR(array)+offset);
+                       offset += INTALIGN(VARSIZE(geom));
+       
+                       if ( TYPE_GETTYPE(geom->type) != POINTTYPE ) continue;
+       
+                       lwpoints[npoints++] =
+                       lwpoint_deserialize(SERIALIZED_FORM(geom));
+       
+                       /* Check SRID homogeneity */
+                       if ( npoints == 1 )
+                       {
+                               /* Get first geometry SRID */
+                               SRID = lwpoints[npoints-1]->SRID;
+                       }
+                       else
+                       {
+                               if ( lwpoints[npoints-1]->SRID != SRID )
+                               {
+                                       elog(ERROR,
+                                       "Operation on mixed SRID geometries");
+                                       PG_RETURN_NULL();
+                               }
+                       }
+       
+                       POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: element %d deserialized",
+                               i);
                }
-               else
+
+               /* Advance NULL bitmap */
+               if (bitmap)
                {
-                       if ( lwpoints[npoints-1]->SRID != SRID )
+                       bitmask <<= 1;
+                       if (bitmask == 0x100)
                        {
-                               elog(ERROR,
-                                    "Operation on mixed SRID geometries");
-                               PG_RETURN_NULL();
+                               bitmap++;
+                               bitmask = 1;
                        }
                }
-
-               POSTGIS_DEBUGF(3, "LWGEOM_makeline_garray: element %d deserialized",
-                              i);
        }
 
        /* Return null on 0-points input array */