Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed compilation issue with PostgreSQL 12 and C90 array size compata… #14

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion path.c
Original file line number Diff line number Diff line change
Expand Up @@ -513,13 +513,21 @@ spherepath_in(PG_FUNCTION_ARGS)
nelem = get_path_count();
if (nelem > 1)
{
SPoint arr[nelem];
SPoint* arr = (SPoint*)malloc(nelem*sizeof(SPoint));
if (arr == NULL) {
reset_buffer();
elog(ERROR, "spherepath_in: could not allocate array");
PG_RETURN_NULL();
}

for (i = 0; i < nelem; i++)
{
get_path_elem(i, &arr[i].lng, &arr[i].lat);
}
path = spherepath_from_array(&arr[0], nelem);

//free array
free(arr);
}
else
{
Expand Down
21 changes: 19 additions & 2 deletions polygon.c
Original file line number Diff line number Diff line change
Expand Up @@ -824,13 +824,21 @@ spherepoly_in(PG_FUNCTION_ARGS)
nelem = get_path_count();
if (nelem > 2)
{
SPoint arr[nelem];
// allocate arr
SPoint* arr = (SPoint *)malloc(nelem * sizeof(SPoint));
if (arr == NULL) {
reset_buffer();
elog(ERROR, "spherepoly_in: Could not allocate array.");
PG_RETURN_NULL();
}

for (i = 0; i < nelem; i++)
{
get_path_elem(i, &arr[i].lng, &arr[i].lat);
}
poly = spherepoly_from_array(&arr[0], nelem);
// free allocated array
free(arr);
}
else
{
Expand Down Expand Up @@ -892,11 +900,17 @@ spherepoly_area(PG_FUNCTION_ARGS)
{
SPOLY *poly = PG_GETARG_SPOLY(0);
int32 i;
SPoint s[poly->npts + 2];
SPoint *s = (SPoint*)malloc((poly->npts+2)*sizeof(SPoint));
//SPoint s[poly->npts + 2];
SPoint stmp[2];
SEuler se;
float8 sum = 0.0;

if (s == NULL) {
elog(ERROR, "spherepoly_area: Could not allocate array.");
PG_RETURN_NULL();
}

memcpy((void *) &s[1],
(void *) &poly->p[0],
poly->npts * sizeof(SPoint));
Expand Down Expand Up @@ -936,6 +950,9 @@ spherepoly_area(PG_FUNCTION_ARGS)
sum = 0.0;
}

// free array
free(s);

PG_RETURN_FLOAT8(sum);
}

Expand Down