#4059 closed defect (fixed)
Please avoid use of variable length array
Reported by: | vmo | Owned by: | pramsey |
---|---|---|---|
Priority: | medium | Milestone: | PostGIS 2.5.0 |
Component: | postgis | Version: | master |
Keywords: | Cc: |
Description
While trying to compile with Microsoft Visual, I came across this use of variable length array (in geography_centroid.c) because the compiler doesn't support those.
case MULTIPOINTTYPE: { LWMPOINT* mpoints = lwgeom_as_lwmpoint(lwgeom); /* average between all points */ uint32_t size = mpoints->ngeoms; POINT3DM points[size]; uint32_t i; for (i = 0; i < size; i++) { points[i].x = lwpoint_get_x(mpoints->geoms[i]); points[i].y = lwpoint_get_y(mpoints->geoms[i]); points[i].m = 1; } lwpoint_out = geography_centroid_from_wpoints(srid, points, size); break; }
This is a tad dangerous IMHO with geometries, since they can be arbitrarily large (let's take the geographic centroid of a pointcloud
Attachments (1)
Change History (6)
by , 7 years ago
comment:3 by , 7 years ago
You're very welcome, tracking vla is for the moment the only useful thing visual does.
As a side note: I also have to replace
const size_t sz=4;
by
# define sz 4
if sz is used to dimension an array… because, for visual, sz is not a const expression…
Note:
See TracTickets
for help on using tickets.
replace vla with plain old palloc