]> granicus.if.org Git - postgis/commitdiff
Fix for GBT #116, EMPTY hex polygon no longer causes crash.
authorPaul Ramsey <pramsey@cleverelephant.ca>
Sun, 8 Mar 2009 15:37:27 +0000 (15:37 +0000)
committerPaul Ramsey <pramsey@cleverelephant.ca>
Sun, 8 Mar 2009 15:37:27 +0000 (15:37 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@3803 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom_api.c

index 8607cacf2c83414f3c4953fae7e65c488c3cf589..28b0a3f7b16f70a2a74bff20e41a8be76bbd5c86 100644 (file)
@@ -1645,8 +1645,8 @@ compute_serialized_box3d(uchar *srl)
 {
        int type = lwgeom_getType(srl[0]);
        int t;
-       uchar *loc;
-       uint32 ngeoms;
+       uchar *loc = srl;
+       uint32 nelems;
        BOX3D *result;
        BOX3D b1;
        int sub_size;
@@ -1654,6 +1654,23 @@ compute_serialized_box3d(uchar *srl)
 
        LWDEBUGF(2, "compute_serialized_box3d called on type %d", type);
 
+       loc += 1; /* Move past the 'type' byte. */
+
+       if (lwgeom_hasBBOX(srl[0]))
+       {
+               loc += sizeof(BOX2DFLOAT4); /* Move past the bbox */
+       }
+
+       if (lwgeom_hasSRID(srl[0]) )
+       {
+               loc +=4; /* Move past the SRID */
+       }
+
+       nelems = lw_get_uint32(loc);
+
+       /* No elements? This is an EMPTY geometry. */
+       if ( nelems == 0 ) return NULL;
+
        if (type == POINTTYPE)
        {
                LWPOINT *pt = lwpoint_deserialize(srl);
@@ -1700,24 +1717,11 @@ compute_serialized_box3d(uchar *srl)
                return NULL;
        }
 
-       loc = srl+1;
-
-       if (lwgeom_hasBBOX(srl[0]))
-       {
-               loc += sizeof(BOX2DFLOAT4);
-       }
-
-       if (lwgeom_hasSRID(srl[0]) )
-       {
-               loc +=4;
-       }
-
-       ngeoms = lw_get_uint32(loc);
        loc += 4;
 
        /* each sub-type */
        result = NULL;
-       for (t=0; t<ngeoms; t++)
+       for (t=0; t<nelems; t++)
        {
                if ( compute_serialized_box3d_p(loc, &b1) ) 
                {