From: Sandro Santilli Date: Tue, 13 Aug 2013 07:27:23 +0000 (+0000) Subject: Fix short allocation of edge to curves store (#2425) X-Git-Tag: 2.2.0rc1~1406 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=6a21d5ece07d335454652e7b7889463749d18cd9;p=postgis Fix short allocation of edge to curves store (#2425) git-svn-id: http://svn.osgeo.org/postgis/trunk@11789 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_ptarray.c b/liblwgeom/cunit/cu_ptarray.c index aec35740f..369720f0e 100644 --- a/liblwgeom/cunit/cu_ptarray.c +++ b/liblwgeom/cunit/cu_ptarray.c @@ -405,7 +405,17 @@ static void test_ptarray_desegmentize() // printf("%s\n", str); lwfree(str); - // See http://trac.osgeo.org/postgis/ticket/2412 + // See http://trac.osgeo.org/postgis/ticket/2425 + // and http://trac.osgeo.org/postgis/ticket/2420 + in = lwgeom_from_text("LINESTRING(0 0,10 0,10 10,0 10,0 0)"); + out = lwgeom_desegmentize(in); + str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL); + CU_ASSERT_STRING_EQUAL(str, "LINESTRING(0 0,10 0,10 10,0 10,0 0)"); + lwgeom_free(in); + lwgeom_free(out); + lwfree(str); + + // See http://trac.osgeo.org/postgis/ticket/2412 in = lwgeom_from_text("LINESTRING(0 0, 1 1)"); out = lwgeom_desegmentize(in); str = lwgeom_to_wkt(out, WKT_ISO, 8, NULL); @@ -414,6 +424,7 @@ static void test_ptarray_desegmentize() lwgeom_free(in); lwgeom_free(out); lwfree(str); + } static void test_ptarray_contains_point() diff --git a/liblwgeom/lwsegmentize.c b/liblwgeom/lwsegmentize.c index 991cb1f6b..1db038e20 100644 --- a/liblwgeom/lwsegmentize.c +++ b/liblwgeom/lwsegmentize.c @@ -17,7 +17,7 @@ #include "liblwgeom_internal.h" -//#define POSTGIS_DEBUG_LEVEL 4 +/* #define POSTGIS_DEBUG_LEVEL 4 */ #include "lwgeom_log.h" @@ -614,8 +614,8 @@ pta_desegmentize(POINTARRAY *points, int type, int srid) /* Allocate our result array of vertices that are part of arcs */ num_edges = points->npoints - 1; - edges_in_arcs = lwalloc(num_edges); - memset(edges_in_arcs, 0, num_edges); + edges_in_arcs = lwalloc(num_edges + 1); + memset(edges_in_arcs, 0, num_edges + 1); /* We make a candidate arc of the first two edges, */ /* And then see if the next edge follows it */