]> granicus.if.org Git - postgis/commitdiff
Fix memory error in ST_ClipByBox2D (#2950)
authorSandro Santilli <strk@keybit.net>
Thu, 2 Oct 2014 08:03:25 +0000 (08:03 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 2 Oct 2014 08:03:25 +0000 (08:03 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@13028 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_clip_by_rect.c
postgis/lwgeom_geos.c
regress/clipbybox2d.sql
regress/clipbybox2d_expected

index f681eb4130876fa4c09a27f0721bbc3548fdb00e..e962e32537a20df70a73a31e6f37698b817d537e 100644 (file)
@@ -42,6 +42,14 @@ static void test_lwgeom_clip_by_rect(void)
        CU_ASSERT_STRING_EQUAL(wkt, tmp)
        lwfree(tmp); lwgeom_free(out); lwgeom_free(in);
 
+  /* Disjoint polygon */
+       wkt = "POLYGON((311017 4773762,311016 4773749,311006 4773744,310990 4773748,310980 4773758,310985 4773771,311003 4773776,311017 4773762))";
+       in = lwgeom_from_wkt(wkt, LW_PARSER_CHECK_NONE);
+       out = lwgeom_clip_by_rect(in, -80, -80, 80, 80);
+       //tmp = lwgeom_to_ewkt(out); printf("%s\n", tmp); lwfree(tmp);
+       CU_ASSERT(lwgeom_is_empty(out));
+       lwgeom_free(out); lwgeom_free(in);
+
 #endif /* POSTGIS_GEOS_VERSION >= 35 */
 }
 
index ac559fdeafc14f0698aba9bc1fcab0fa8ea68ac8..ce3a5092f932c3743c58a970cbfdf46c51b53bb2 100644 (file)
@@ -1671,7 +1671,7 @@ Datum ST_ClipByBox2d(PG_FUNCTION_ARGS)
        if ( LW_FALSE == gbox_overlaps_2d(bbox1, bbox2) ) {
                lwresult = lwgeom_construct_empty(lwgeom1->type, lwgeom1->srid, 0, 0);
                lwgeom_free(lwgeom1);
-               PG_FREE_IF_COPY(geom1, 1);
+               PG_FREE_IF_COPY(geom1, 0);
                result = geometry_serialize(lwresult) ;
                lwgeom_free(lwresult) ;
                PG_RETURN_POINTER(result);
index 1f863de34291fdea0b92c976473af5e6559c24e2..1c9a4a6f7b57d63ae7231d9613144395f3f32e58 100644 (file)
@@ -15,4 +15,9 @@ SELECT ST_AsText(ST_ClipByBox2d('POLYGON((0 0,5 4,5 6,0 10,10 10,5 6,5 4,10 0,0
 SELECT ST_AsText(ST_ClipByBox2d(
   '0103000000010000000400000000000000000000000000000000000000000000000000244000000000000000000000000000002440000000000000244000000000000000000000000000002440'
   , ST_MakeEnvelope(2,2,5,5)));
-
+-- Geometry disjoint from box, from a table
+-- See http://trac.osgeo.org/postgis/ticket/2950
+CREATE TEMPORARY TABLE t AS SELECT
+'SRID=3857;POLYGON((41 20,41 0,21 0,1 20,1 40,21 40,41 20))'
+::geometry g;
+SELECT ST_AsEWKT(ST_ClipByBox2d(g, ST_MakeEnvelope(-20,-20,-10,-10))) FROM t;
index 299e0b6eb5a6f2aac52c1bd1f38c20543685ca68..8243e44fafff5c17eb94ff467cf07a0a10820ea6 100644 (file)
@@ -5,3 +5,4 @@ POINT(2 2)
 POLYGON((2 2,8 2,2 8,8 8,2 2))
 POLYGON((2.5 2,5 4,5 5,5 4,7.5 2,2.5 2))
 POLYGON((2 2,2 5,5 5,5 2,2 2))
+SRID=3857;POLYGON EMPTY