From 9acf63d0cb7958a3d1c5ffa901193e2b5bbc43f4 Mon Sep 17 00:00:00 2001 From: Sandro Santilli Date: Thu, 12 Jan 2012 08:52:03 +0000 Subject: [PATCH] Fix a bug in gserialized_read_gbox_p reading garbage in EMPTY point Includes cunit test. Fixes #1458. git-svn-id: http://svn.osgeo.org/postgis/trunk@8785 b70326c6-7e19-0410-871a-916f4a2858ee --- liblwgeom/cunit/cu_libgeom.c | 31 +++++++++++++++++++++++++++---- liblwgeom/g_serialized.c | 8 ++++++++ 2 files changed, 35 insertions(+), 4 deletions(-) diff --git a/liblwgeom/cunit/cu_libgeom.c b/liblwgeom/cunit/cu_libgeom.c index 8adb720ca..0658921ca 100644 --- a/liblwgeom/cunit/cu_libgeom.c +++ b/liblwgeom/cunit/cu_libgeom.c @@ -232,32 +232,55 @@ static void test_lwgeom_from_gserialized(void) char ewkt[][512] = { + "POINT EMPTY", "POINT(0 0.2)", + "LINESTRING EMPTY", "LINESTRING(-1 -1,-1 2.5,2 2,2 -1)", + "MULTIPOINT EMPTY", "MULTIPOINT(0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9,0.9 0.9)", + "SRID=1;MULTILINESTRING EMPTY", "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))", "SRID=1;MULTILINESTRING((-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1),(-1 -1,-1 2.5,2 2,2 -1))", "POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))", + "POLYGON EMPTY", "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0))", + "SRID=4326;POLYGON EMPTY", "SRID=4326;POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))", "SRID=100000;POLYGON((-1 -1 3,-1 2.5 3,2 2 3,2 -1 3,-1 -1 3),(0 0 3,0 1 3,1 1 3,1 0 3,0 0 3),(-0.5 -0.5 3,-0.5 -0.4 3,-0.4 -0.4 3,-0.4 -0.5 3,-0.5 -0.5 3))", "SRID=4326;MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)),((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5)))", + "SRID=4326;MULTIPOLYGON EMPTY", "SRID=4326;GEOMETRYCOLLECTION(POINT(0 1),POLYGON((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0)),MULTIPOLYGON(((-1 -1,-1 2.5,2 2,2 -1,-1 -1),(0 0,0 1,1 1,1 0,0 0),(-0.5 -0.5,-0.5 -0.4,-0.4 -0.4,-0.4 -0.5,-0.5 -0.5))))", + "SRID=4326;GEOMETRYCOLLECTION EMPTY", + "SRID=4326;GEOMETRYCOLLECTION(POINT EMPTY, MULTIPOLYGON EMPTY)", "MULTICURVE((5 5 1 3,3 5 2 2,3 3 3 1,0 3 1 1),CIRCULARSTRING(0 0 0 0,0.26794 1 3 -2,0.5857864 1.414213 1 2))", "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING(-2 0,-1 -1,0 0,1 -1,2 0,0 2,-2 0),(-1 0,0 0.5,1 0,0 1,-1 0)),((7 8,10 10,6 14,4 11,7 8)))", + "MULTISURFACE(CURVEPOLYGON(CIRCULARSTRING EMPTY))", }; for ( i = 0; i < 13; i++ ) { + LWGEOM* geom2; + in_ewkt = ewkt[i]; geom = lwgeom_from_wkt(in_ewkt, LW_PARSER_CHECK_NONE); + lwgeom_add_bbox(geom); + if ( geom->bbox ) gbox_float_round(geom->bbox); g = gserialized_from_lwgeom(geom, 0, 0); - lwgeom_free(geom); - geom = lwgeom_from_gserialized(g); - out_ewkt = lwgeom_to_ewkt(geom); - //printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); + + geom2 = lwgeom_from_gserialized(g); + out_ewkt = lwgeom_to_ewkt(geom2); + + /* printf("\n in = %s\nout = %s\n", in_ewkt, out_ewkt); */ CU_ASSERT_STRING_EQUAL(in_ewkt, out_ewkt); + + /* either both or none of the bboxes are null */ + CU_ASSERT( (geom->bbox != NULL) || (geom2->bbox == NULL) ); + + /* either both are null or they are the same */ + CU_ASSERT(geom->bbox == NULL || gbox_same(geom->bbox, geom2->bbox)); + lwgeom_free(geom); + lwgeom_free(geom2); lwfree(g); lwfree(out_ewkt); } diff --git a/liblwgeom/g_serialized.c b/liblwgeom/g_serialized.c index 9006cbf44..58224cb68 100644 --- a/liblwgeom/g_serialized.c +++ b/liblwgeom/g_serialized.c @@ -175,6 +175,14 @@ int gserialized_read_gbox_p(const GSERIALIZED *g, GBOX *gbox) { int i = 1; /* Start past */ double *dptr = (double*)(g->data); + + /* Read the empty flag */ + int *iptr = (int*)(g->data); + int isempty = (iptr[1] == 0); + + /* EMPTY point has no box */ + if ( isempty ) return LW_FAILURE; + gbox->xmin = gbox->xmax = dptr[i++]; gbox->ymin = gbox->ymax = dptr[i++]; if ( FLAGS_GET_Z(g->flags) ) -- 2.50.1