From: Sandro Santilli Date: Thu, 26 Jan 2012 12:59:51 +0000 (+0000) Subject: Don't let ptarray_append_ptarray change read-only pointarrays X-Git-Tag: 2.0.0alpha3~66 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e916935621276a16052df649217a6686cb12ce0f;p=postgis Don't let ptarray_append_ptarray change read-only pointarrays git-svn-id: http://svn.osgeo.org/postgis/trunk@8929 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_ptarray.c b/liblwgeom/cunit/cu_ptarray.c index 26e9bf604..c6b56b7ef 100644 --- a/liblwgeom/cunit/cu_ptarray.c +++ b/liblwgeom/cunit/cu_ptarray.c @@ -145,6 +145,27 @@ static void test_ptarray_append_ptarray(void) lwline_free(line2); lwline_free(line1); + /* Appending a read-only pointarray is allowed */ + line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 10, 10 0)")); + line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 0,11 0)")); + FLAGS_SET_READONLY(line2->points->flags, 1); + ret = ptarray_append_ptarray(line1->points, line2->points, -1); + CU_ASSERT(ret == LW_SUCCESS); + wkt = lwgeom_to_text(lwline_as_lwgeom(line1)); + CU_ASSERT_STRING_EQUAL(wkt, "LINESTRING(0 10,10 0,11 0)"); + lwfree(wkt); + lwline_free(line2); + lwline_free(line1); + + /* Appending to a read-only pointarray is forbidden */ + line1 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 10, 10 0)")); + line2 = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(10 0,11 0)")); + FLAGS_SET_READONLY(line1->points->flags, 1); + ret = ptarray_append_ptarray(line1->points, line2->points, -1); + CU_ASSERT(ret == LW_FAILURE); + lwline_free(line2); + lwline_free(line1); + } static void test_ptarray_locate_point(void) diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index cd24c6316..3eff56546 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -185,7 +185,13 @@ ptarray_append_ptarray(POINTARRAY *pa1, POINTARRAY *pa2, double gap_tolerance) if ( ! npoints ) return LW_SUCCESS; /* nothing more to do */ - if( pa1->flags != pa2->flags ) + if( FLAGS_GET_READONLY(pa1->flags) ) + { + lwerror("ptarray_append_ptarray: target pointarray is read-only"); + return LW_FAILURE; + } + + if( FLAGS_GET_ZM(pa1->flags) != FLAGS_GET_ZM(pa2->flags) ) { lwerror("ptarray_append_ptarray: appending mixed dimensionality is not allowed"); return LW_FAILURE;