Opened 7 years ago

Closed 7 years ago

Last modified 6 years ago

#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)

vla.patch (1.9 KB ) - added by vmo 7 years ago.
replace vla with plain old palloc

Download all attachments as: .zip

Change History (6)

by vmo, 7 years ago

Attachment: vla.patch added

replace vla with plain old palloc

comment:1 by strk, 7 years ago

Resolution: fixed
Status: newclosed

In 16508:

Avoid incompatible automatic variable length array

Patch by vmo
Closes #4059

comment:2 by strk, 7 years ago

Thanks !

comment:3 by vmo, 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…

comment:4 by strk, 7 years ago

vla is not valid ansi either IIRC, so I'm happy to drop

comment:5 by pramsey, 6 years ago

In 16970:

Remove use of VLA from geography centroid
References #4059

Note: See TracTickets for help on using tickets.