]> granicus.if.org Git - postgis/commitdiff
Don't let ptarray_append_ptarray change read-only pointarrays
authorSandro Santilli <strk@keybit.net>
Thu, 26 Jan 2012 12:59:51 +0000 (12:59 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 26 Jan 2012 12:59:51 +0000 (12:59 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@8929 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/cunit/cu_ptarray.c
liblwgeom/ptarray.c

index 26e9bf604ca47e6755953d64b7bc7a2c1f73552b..c6b56b7ef04cecd6ba50f2f0ad75755e8f053930 100644 (file)
@@ -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)
index cd24c6316824ec23e69a5aa1d1112d43e3266407..3eff56546a591e633fbd33237bee2da70ba17060 100644 (file)
@@ -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;