]> granicus.if.org Git - postgis/commitdiff
Check args passed to ptarray_set_point4d
authorSandro Santilli <strk@keybit.net>
Thu, 1 Mar 2012 12:25:50 +0000 (12:25 +0000)
committerSandro Santilli <strk@keybit.net>
Thu, 1 Mar 2012 12:25:50 +0000 (12:25 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9363 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/liblwgeom.h.in
liblwgeom/lwgeom_api.c
liblwgeom/ptarray.c

index 1623413d4bc59688b06f159eb898bc15d5b3d36d..9b7ae80f50ac0cc9a506d6147541c50fed7abacc 100644 (file)
@@ -770,6 +770,7 @@ extern int getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point);
  * dimension, the appropriate ordinate values
  * will be extracted from it
  *
+ * N must be a valid point index 
  */
 extern void ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d);
 
index 78edb496b2fb538acb9342274c84c073d4e99866..8c46bd1666107c4e942f755cf83c4fa73376c73f 100644 (file)
@@ -17,6 +17,7 @@
 #include <float.h>
 #include <stdio.h>
 #include <errno.h>
+#include <assert.h>
 
 /*
  * Lower this to reduce integrity checks
@@ -457,6 +458,7 @@ getPoint2d_p(const POINTARRAY *pa, int n, POINT2D *point)
 void
 ptarray_set_point4d(POINTARRAY *pa, int n, const POINT4D *p4d)
 {
+       assert(n >= 0 && n < pa->npoints);
        uint8_t *ptr=getPoint_internal(pa, n);
        switch ( FLAGS_GET_ZM(pa->flags) )
        {
index 53fdab043717c0c3acf11910393d574dc2c10ee4..b623c02e25ddc8a9e33f49d3522ba9053aca0889 100644 (file)
@@ -125,13 +125,13 @@ ptarray_insert_point(POINTARRAY *pa, const POINT4D *p, int where)
                LWDEBUGF(5,"copying %d bytes to start vertex %d from start vertex %d", copy_size, where+1, where);
        }
        
+       /* We have one more point */
+       ++pa->npoints;
+       
        /* Copy the new point into the gap */
        ptarray_set_point4d(pa, where, p);
        LWDEBUGF(5,"copying new point to start vertex %d", point_size, where);
        
-       /* We have one more point */
-       pa->npoints++;
-       
        return LW_SUCCESS;
 }