-
Notifications
You must be signed in to change notification settings - Fork 760
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
databases/pgsphere: stop using VLAs to fix PG12 compilation
PR: 248657 Reported by: [email protected] Obtained from: akorotkov/pgsphere#14 Sponsored by: BBOX.io git-svn-id: svn+ssh://svn.freebsd.org/ports/head@548447 35697150-7ecd-e111-bb59-0022644237b5
- Loading branch information
kbowling
committed
Sep 13, 2020
1 parent
9861f8a
commit aaf997b
Showing
3 changed files
with
80 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,7 +3,7 @@ | |
|
||
PORTNAME= pgsphere | ||
PORTVERSION= 1.1.5 | ||
PORTREVISION= 3 | ||
PORTREVISION= 4 | ||
CATEGORIES= databases geography | ||
|
||
MAINTAINER= [email protected] | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
--- path.c.orig 2019-10-30 10:18:38 UTC | ||
+++ path.c | ||
@@ -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 | ||
{ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
--- polygon.c.orig 2019-10-30 10:18:38 UTC | ||
+++ polygon.c | ||
@@ -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 | ||
{ | ||
@@ -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)); | ||
@@ -935,6 +949,9 @@ spherepoly_area(PG_FUNCTION_ARGS) | ||
{ | ||
sum = 0.0; | ||
} | ||
+ | ||
+ // free array | ||
+ free(s); | ||
|
||
PG_RETURN_FLOAT8(sum); | ||
} |