[postgis-tickets] r16970 - Remove use of VLA from geography centroid

Paul Ramsey pramsey at cleverelephant.ca
Thu Nov 1 12:31:24 PDT 2018


Author: pramsey
Date: 2018-11-01 12:31:24 -0700 (Thu, 01 Nov 2018)
New Revision: 16970

Modified:
   branches/2.4/postgis/geography_centroid.c
Log:
Remove use of VLA from geography centroid
References #4059


Modified: branches/2.4/postgis/geography_centroid.c
===================================================================
--- branches/2.4/postgis/geography_centroid.c	2018-10-31 22:02:55 UTC (rev 16969)
+++ branches/2.4/postgis/geography_centroid.c	2018-11-01 19:31:24 UTC (rev 16970)
@@ -105,7 +105,7 @@
 
         /* average between all points */
         uint32_t size = mpoints->ngeoms;
-        POINT3DM points[size];
+        POINT3DM* points = palloc(size*sizeof(POINT3DM));
 
 		uint32_t i;
 		for (i = 0; i < size; i++) {
@@ -115,6 +115,7 @@
         }
 
 		lwpoint_out = geography_centroid_from_wpoints(srid, points, size);
+        pfree(points);
         break;
     }
 
@@ -258,7 +259,7 @@
         size += (mline->geoms[i]->points->npoints - 1) * 2;
     }
 
-    POINT3DM points[size];
+    POINT3DM* points = palloc(size*sizeof(POINT3DM));
     uint32_t j = 0;
 
     for (i = 0; i < mline->ngeoms; i++) {
@@ -295,7 +296,9 @@
         }
     }
 
-    return geography_centroid_from_wpoints(mline->srid, points, size);
+    LWPOINT* result = geography_centroid_from_wpoints(mline->srid, points, size);
+    pfree(points);
+    return result;
 }
 
 
@@ -313,7 +316,7 @@
 		}
     }
 
-    POINT3DM points[size];
+    POINT3DM* points = palloc(size*sizeof(POINT3DM));
     uint32_t j = 0;
 
     /* use first point as reference to create triangles */
@@ -379,6 +382,7 @@
             }
         }
     }
-
-    return geography_centroid_from_wpoints(mpoly->srid, points, size);
+    LWPOINT* result = geography_centroid_from_wpoints(mpoly->srid, points, size);
+    pfree(points);
+    return result;
 }



More information about the postgis-tickets mailing list