]> granicus.if.org Git - postgis/commitdiff
fix variable length arrays
authorSandro Santilli <strk@kbt.io>
Wed, 12 Apr 2017 13:33:53 +0000 (13:33 +0000)
committerSandro Santilli <strk@kbt.io>
Wed, 12 Apr 2017 13:33:53 +0000 (13:33 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@15350 b70326c6-7e19-0410-871a-916f4a2858ee

liblwgeom/lwgeom_geos.c
liblwgeom/lwprint.c
postgis/lwgeom_ogc.c

index 64659dec0ba9e4178e9c53a04c1e0cade5b29122..558b6d7b6071bdc352654dd058a7e995f9f02793 100644 (file)
@@ -1649,23 +1649,6 @@ lwgeom_offsetcurve(const LWLINE *lwline, double size, int quadsegs, int joinStyl
 }
 
 
-static void shuffle(void *array, size_t n, size_t size) {
-    char tmp[size];
-    char *arr = array;
-    size_t stride = size;
-
-    if (n > 1) {
-        size_t i;
-        for (i = 0; i < n - 1; ++i) {
-            size_t rnd = (size_t) rand();
-            size_t j = i + rnd / (RAND_MAX / (n - i) + 1);
-
-            memcpy(tmp, arr + j * stride, size);
-            memcpy(arr + j * stride, arr + i * stride, size);
-            memcpy(arr + i * stride, tmp, size);
-        }
-    }
-}
 
 LWMPOINT*
 lwpoly_to_points(const LWPOLY *lwpoly, int npoints)
@@ -1675,7 +1658,7 @@ lwpoly_to_points(const LWPOLY *lwpoly, int npoints)
        const LWGEOM *lwgeom = (LWGEOM*)lwpoly;
        int sample_npoints, sample_sqrt, sample_width, sample_height;
        double sample_cell_size;
-       int i, j;
+       int i, j, n;
        int iterations = 0;
        int npoints_generated = 0;
        int npoints_tested = 0;
@@ -1687,6 +1670,10 @@ lwpoly_to_points(const LWPOLY *lwpoly, int npoints)
        int srid = lwgeom_get_srid(lwgeom);
        int done = 0;
        int *cells;
+       const size_t size = 2*sizeof(int);
+       char tmp[2*sizeof(int)];
+       const size_t stride = 2*sizeof(int);
+
 
        if (lwgeom_get_type(lwgeom) != POLYGONTYPE)
        {
@@ -1773,7 +1760,22 @@ lwpoly_to_points(const LWPOLY *lwpoly, int npoints)
                        cells[2*(i*sample_height+j)+1] = j;
                }
        }
-       shuffle(cells, sample_height*sample_width, 2*sizeof(int));
+
+       /* shuffle */
+       {
+               n = sample_height*sample_width;
+               if (n > 1) {
+                       for (i = 0; i < n - 1; ++i) {
+                               size_t rnd = (size_t) rand();
+                               size_t j = i + rnd / (RAND_MAX / (n - i) + 1);
+
+                               memcpy(tmp, (char *)cells + j * stride, size);
+                               memcpy((char *)cells + j * stride, (char *)cells + i * stride, size);
+                               memcpy((char *)cells + i * stride, tmp, size);
+                       }
+               }
+       }
+
 
        /* Start testing points */
        while (npoints_generated < npoints)
index 6557ec02a81c219728d735ba0c0edaadf7a1b2d5..649285e565a68a48deb0e7897d628f3e1f06f6f2 100644 (file)
@@ -76,8 +76,8 @@ static void lwprint_normalize_latlon(double *lat, double *lon)
 static char * lwdouble_to_dms(double val, const char *pos_dir_symbol, const char *neg_dir_symbol, const char * format)
 {
        /* 3 numbers, 1 sign or compass dir, and 5 possible strings (degree signs, spaces, misc text, etc) between or around them.*/
-       static int NUM_PIECES = 9;
-       static int WORK_SIZE = 1024;
+#      define NUM_PIECES 9
+#      define WORK_SIZE 1024
        char pieces[NUM_PIECES][WORK_SIZE];
        int current_piece = 0;
        int is_negative = 0;
index 3db1744a1c64cec4e036d583803121996b42b682..5d909c5e9dfdbb5655b0f59a348810d1ff4d68ff 100644 (file)
@@ -177,7 +177,7 @@ Datum geometry_geometrytype(PG_FUNCTION_ARGS)
 {
        GSERIALIZED *gser;
        text *type_text;
-       static int type_str_len = 31;
+#      define type_str_len 31
        char type_str[type_str_len + 1];
 
        /* Read just the header from the toasted tuple */