[postgis-commits] svn - r3804 - branches/1.3/lwgeom

postgis-commits at postgis.refractions.net postgis-commits at postgis.refractions.net
Sun Mar 8 08:43:08 PDT 2009


Author: pramsey
Date: 2009-03-08 08:43:07 -0700 (Sun, 08 Mar 2009)
New Revision: 3804

Modified:
   branches/1.3/lwgeom/lwgeom_api.c
Log:
Fix GBT#116, EMPTY hex polygon no longer causes crash.


Modified: branches/1.3/lwgeom/lwgeom_api.c
===================================================================
--- branches/1.3/lwgeom/lwgeom_api.c	2009-03-08 15:37:27 UTC (rev 3803)
+++ branches/1.3/lwgeom/lwgeom_api.c	2009-03-08 15:43:07 UTC (rev 3804)
@@ -1698,8 +1698,8 @@
 {
 	int type = lwgeom_getType(srl[0]);
 	int t;
-	uchar *loc;
-	uint32 ngeoms;
+	uchar *loc = srl;
+	uint32 nelems;
 	BOX3D *result;
 	BOX3D b1;
 	int sub_size;
@@ -1708,7 +1708,23 @@
 #ifdef PGIS_DEBUG
 lwnotice("compute_serialized_box3d called on type %d", type);
 #endif
+	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);
@@ -1755,24 +1771,11 @@
 		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) ) 
 		{



More information about the postgis-commits mailing list