commit ae53a53246ccb26a6e82fede1a4184b41bcf097d Author: Regina Obe Date: Sat Feb 19 00:21:01 2022 -0500 Fix PG 15 building atoi removed. References #5100 for PostGIS 3.3.0 diff -ur postgis-3.3.2.orig/postgis-2.5.5/postgis/gserialized_typmod.c postgis-3.3.2/postgis-2.5.5/postgis/gserialized_typmod.c --- postgis-3.3.2.orig/postgis-2.5.5/postgis/gserialized_typmod.c 2023-04-09 21:52:47.909294055 +0200 +++ postgis-3.3.2/postgis-2.5.5/postgis/gserialized_typmod.c 2023-04-09 21:55:24.744826310 +0200 @@ -35,7 +35,7 @@ #include "utils/elog.h" #include "utils/array.h" -#include "utils/builtins.h" /* for pg_atoi */ +#include "utils/builtins.h" /* for cstring_to_text */ #include "lib/stringinfo.h" /* For binary input */ #include "catalog/pg_type.h" /* for CSTRINGOID */ @@ -267,8 +267,33 @@ } if ( i == 1 ) /* SRID */ { - int srid = pg_atoi(DatumGetCString(elem_values[i]), - sizeof(int32), '\0'); + char *int_string = DatumGetCString(elem_values[i]); + char *endp; + long l; + int32_t srid; + + errno = 0; + l = strtol(int_string, &endp, 10); + + if (int_string == endp) + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", int_string))); + + if (errno == ERANGE || l < INT_MIN || l > INT_MAX) + ereport(ERROR, + (errcode(ERRCODE_NUMERIC_VALUE_OUT_OF_RANGE), + errmsg("value \"%s\" is out of range for type %s", int_string, + "integer"))); + + if (*endp != '\0') + ereport(ERROR, + (errcode(ERRCODE_INVALID_TEXT_REPRESENTATION), + errmsg("invalid input syntax for type %s: \"%s\"", + "integer", int_string))); + + srid = clamp_srid(l); srid = clamp_srid(srid); POSTGIS_DEBUGF(3, "srid: %d", srid); if ( srid != SRID_UNKNOWN )