Skip to content

Commit ae53a53

Browse files
committed
Fix PG 15 building atoi removed. References #5100 for PostGIS 3.3.0
1 parent 9e14b1d commit ae53a53

File tree

4 files changed

+33
-6
lines changed

4 files changed

+33
-6
lines changed

NEWS

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ PostGIS 3.3.0dev
1313
- GH657, GiST: do not call no-op decompress function (Aliaksandr Kalenik)
1414
- #4912, GiST: fix crash on STORAGE EXTERNAL for geography (Aliaksandr Kalenik)
1515
- ST_ConcaveHull GEOS 3.11+ native implementation (Paul Ramsey, Martin Davis)
16+
- #5100, Support for PostgreSQL 15 (atoi removal) (Laurenz Albe)
1617

1718
* New features*
1819
- ST_Letters creates geometries that look like letters (Paul Ramsey)

postgis/geography_inout.c

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@
3434

3535
#include "utils/elog.h"
3636
#include "utils/array.h"
37-
#include "utils/builtins.h" /* for pg_atoi */
37+
#include "utils/builtins.h" /* for text_to_cstring */
3838
#include "lib/stringinfo.h" /* For binary input */
3939
#include "catalog/pg_type.h" /* for CSTRINGOID, INT4OID */
4040

postgis/gserialized_typmod.c

+29-3
Original file line numberDiff line numberDiff line change
@@ -31,10 +31,11 @@
3131
#include <float.h>
3232
#include <string.h>
3333
#include <stdio.h>
34+
#include <errno.h>
3435

3536
#include "utils/elog.h"
3637
#include "utils/array.h"
37-
#include "utils/builtins.h" /* for pg_atoi */
38+
#include "utils/builtins.h" /* for cstring_to_text */
3839
#include "lib/stringinfo.h" /* For binary input */
3940
#include "catalog/pg_type.h" /* for CSTRINGOID */
4041

@@ -272,8 +273,33 @@ static uint32 gserialized_typmod_in(ArrayType *arr, int is_geography)
272273
}
273274
if ( i == 1 ) /* SRID */
274275
{
275-
int32_t srid = pg_atoi(DatumGetCString(elem_values[i]), sizeof(int32), '\0');
276-
srid = clamp_srid(srid);
276+
char *int_string = DatumGetCString(elem_values[i]);
277+
char *endp;
278+
long l;
279+
int32_t srid;
280+
281+
errno = 0;
282+
l = strtol(int_string, &endp, 10);
283+
284+
if (int_string == endp)
285+
ereport(ERROR,
286+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
287+
errmsg("invalid input syntax for type %s: \"%s\"",
288+
"integer", int_string)));
289+
290+
if (errno == ERANGE || l < INT_MIN || l > INT_MAX)
291+
ereport(ERROR,
292+
(errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE),
293+
errmsg("value \"%s\" is out of range for type %s", int_string,
294+
"integer")));
295+
296+
if (*endp != '\0')
297+
ereport(ERROR,
298+
(errcode(ERRCODE_INVALID_TEXT_REPRESENTATION),
299+
errmsg("invalid input syntax for type %s: \"%s\"",
300+
"integer", int_string)));
301+
302+
srid = clamp_srid(l);
277303
POSTGIS_DEBUGF(3, "srid: %d", srid);
278304
if ( srid != SRID_UNKNOWN )
279305
{

postgis/lwgeom_geos.c

+2-2
Original file line numberDiff line numberDiff line change
@@ -2986,8 +2986,8 @@ Datum clusterintersecting_garray(PG_FUNCTION_ARGS)
29862986
char elmalign;
29872987

29882988
/* Null array, null geometry (should be empty?) */
2989-
if (PG_ARGISNULL(0))
2990-
PG_RETURN_NULL();
2989+
if (PG_ARGISNULL(0))
2990+
PG_RETURN_NULL();
29912991

29922992
array = PG_GETARG_ARRAYTYPE_P(0);
29932993
nelems = array_nelems_not_null(array);

0 commit comments

Comments
 (0)