From 9a1b1f7fcfdf879f5d9046515468a6dbca87c0a7 Mon Sep 17 00:00:00 2001 From: Miguel Gomes Date: Tue, 24 Dec 2019 15:27:22 +0000 Subject: [PATCH] Fixed compilation issue with PostgreSQL 12 and C90 array size compatability. Signed-off-by: Miguel Gomes --- path.c | 10 +++++++++- polygon.c | 21 +++++++++++++++++++-- 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/path.c b/path.c index 45c8cb6..db6c61e 100644 --- a/path.c +++ b/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 { diff --git a/polygon.c b/polygon.c index ecc5f87..5df3b06 100644 --- a/polygon.c +++ b/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)); @@ -936,6 +950,9 @@ spherepoly_area(PG_FUNCTION_ARGS) sum = 0.0; } + // free array + free(s); + PG_RETURN_FLOAT8(sum); }