[postgis-tickets] [SCM] PostGIS branch stable-3.2 updated. 3.2.2-4-g0a4263016
git at osgeo.org
git at osgeo.org
Mon Jul 25 15:26:22 PDT 2022
This is an automated email from the git hooks/post-receive script. It was
generated because a ref change was pushed to the repository containing
the project "PostGIS".
The branch, stable-3.2 has been updated
via 0a426301696a64bd1db11e7f8c72814e807e16b1 (commit)
from d7d8b5526500055c50c27bcd4d3e21cbf616e531 (commit)
Those revisions listed above that are new to this repository have
not appeared on any other notification email; so we list those
revisions in full, below.
- Log -----------------------------------------------------------------
commit 0a426301696a64bd1db11e7f8c72814e807e16b1
Author: Paul Ramsey <pramsey at cleverelephant.ca>
Date: Mon Jul 25 14:58:45 2022 -0700
Move to snprintf where easily done
diff --git a/extras/wkb_reader/readwkb.c b/extras/wkb_reader/readwkb.c
index 8f6530160..a85454af3 100644
--- a/extras/wkb_reader/readwkb.c
+++ b/extras/wkb_reader/readwkb.c
@@ -134,7 +134,7 @@ main()
* fetch rows from the pg_database, the system catalog of
* databases
*/
- sprintf(query_str, "DECLARE mycursor BINARY CURSOR FOR select text(num), asbinary(the_geom,'ndr') as wkb from %s", table_name);
+ snprintf(query_str, sizeof(query_str), "DECLARE mycursor BINARY CURSOR FOR select text(num), asbinary(the_geom,'ndr') as wkb from %s", table_name);
printf(query_str);
printf("\n");
diff --git a/liblwgeom/lwgeom_debug.c b/liblwgeom/lwgeom_debug.c
index e3d7b3a6e..93cb1c56d 100644
--- a/liblwgeom/lwgeom_debug.c
+++ b/liblwgeom/lwgeom_debug.c
@@ -57,10 +57,11 @@ lwpoint_summary(LWPOINT *point, int offset)
char *result;
char *pad="";
char *zmflags = lwgeom_flagchars((LWGEOM*)point);
+ size_t sz = 128+offset;
- result = (char *)lwalloc(128+offset);
+ result = (char *)lwalloc(sz);
- sprintf(result, "%*.s%s[%s]",
+ snprintf(result, sz, "%*.s%s[%s]",
offset, pad, lwtype_name(point->type),
zmflags);
return result;
@@ -72,10 +73,11 @@ lwline_summary(LWLINE *line, int offset)
char *result;
char *pad="";
char *zmflags = lwgeom_flagchars((LWGEOM*)line);
+ size_t sz = 128+offset;
- result = (char *)lwalloc(128+offset);
+ result = (char *)lwalloc(sz);
- sprintf(result, "%*.s%s[%s] with %d points",
+ snprintf(result, sz, "%*.s%s[%s] with %d points",
offset, pad, lwtype_name(line->type),
zmflags,
line->points->npoints);
@@ -98,7 +100,7 @@ lwcollection_summary(LWCOLLECTION *col, int offset)
result = (char *)lwalloc(size);
- sprintf(result, "%*.s%s[%s] with %d element%s",
+ snprintf(result, size, "%*.s%s[%s] with %d element%s",
offset, pad, lwtype_name(col->type),
zmflags,
col->ngeoms,
@@ -139,7 +141,7 @@ lwpoly_summary(LWPOLY *poly, int offset)
result = (char *)lwalloc(size);
- sprintf(result, "%*.s%s[%s] with %i ring%s",
+ snprintf(result, size, "%*.s%s[%s] with %i ring%s",
offset, pad, lwtype_name(poly->type),
zmflags,
poly->nrings,
@@ -149,7 +151,7 @@ lwpoly_summary(LWPOLY *poly, int offset)
for (i=0; i<poly->nrings; i++)
{
- sprintf(tmp,"%s ring %i has %i points",
+ snprintf(tmp, sizeof(tmp), "%s ring %i has %i points",
pad, i, poly->rings[i]->npoints);
if ( i > 0 ) strcat(result,nl);
strcat(result,tmp);
@@ -190,7 +192,7 @@ lwgeom_summary(const LWGEOM *lwgeom, int offset)
return lwcollection_summary((LWCOLLECTION *)lwgeom, offset);
default:
result = (char *)lwalloc(256);
- sprintf(result, "Object is of unknown type: %d",
+ snprintf(result, 256, "Object is of unknown type: %d",
lwgeom->type);
return result;
}
diff --git a/liblwgeom/lwprint.c b/liblwgeom/lwprint.c
index dc4a6b248..68bb51b2e 100644
--- a/liblwgeom/lwprint.c
+++ b/liblwgeom/lwprint.c
@@ -357,7 +357,7 @@ static char * lwdouble_to_dms(double val, const char *pos_dir_symbol, const char
}
if(deg_piece >= 0)
{
- sprintf(pieces[deg_piece], "%*.*f", deg_digits, deg_dec_digits, degrees);
+ snprintf(pieces[deg_piece], WORK_SIZE, "%*.*f", deg_digits, deg_dec_digits, degrees);
}
if (min_piece >= 0)
@@ -367,7 +367,7 @@ static char * lwdouble_to_dms(double val, const char *pos_dir_symbol, const char
{
lwerror("Bad format, minutes (MM.MMM) number of digits was greater than our working limit.");
}
- sprintf(pieces[min_piece], "%*.*f", min_digits, min_dec_digits, minutes);
+ snprintf(pieces[min_piece], WORK_SIZE, "%*.*f", min_digits, min_dec_digits, minutes);
}
if (sec_piece >= 0)
{
@@ -376,7 +376,7 @@ static char * lwdouble_to_dms(double val, const char *pos_dir_symbol, const char
{
lwerror("Bad format, seconds (SS.SSS) number of digits was greater than our working limit.");
}
- sprintf(pieces[sec_piece], "%*.*f", sec_digits, sec_dec_digits, seconds);
+ snprintf(pieces[sec_piece], WORK_SIZE, "%*.*f", sec_digits, sec_dec_digits, seconds);
}
/* Allocate space for the result. Leave plenty of room for excess digits, negative sign, etc.*/
@@ -404,6 +404,7 @@ static char * lwdoubles_to_latlon(double lat, double lon, const char * format)
char * lat_text;
char * lon_text;
char * result;
+ size_t sz;
/* Normalize lat/lon to the normal (-90 to 90, -180 to 180) range. */
lwprint_normalize_latlon(&lat, &lon);
@@ -412,8 +413,9 @@ static char * lwdoubles_to_latlon(double lat, double lon, const char * format)
lon_text = lwdouble_to_dms(lon, "E", "W", format);
/* lat + lon + a space between + the null terminator. */
- result = (char*)lwalloc(strlen(lat_text) + strlen(lon_text) + 2);
- sprintf(result, "%s %s", lat_text, lon_text);
+ sz = strlen(lat_text) + strlen(lon_text) + 2;
+ result = (char*)lwalloc(sz);
+ snprintf(result, sz, "%s %s", lat_text, lon_text);
lwfree(lat_text);
lwfree(lon_text);
return result;
diff --git a/loader/shp2pgsql-gui.c b/loader/shp2pgsql-gui.c
index ebb67e46d..eb22852bc 100644
--- a/loader/shp2pgsql-gui.c
+++ b/loader/shp2pgsql-gui.c
@@ -690,6 +690,7 @@ update_table_chooser_from_database()
/* Now insert one row for each query result */
for (i = 0; i < PQntuples(result); i++)
{
+ size_t sz;
gtk_list_store_insert_before(chooser_table_list_store, &iter, NULL);
/* Look up the geo columns; if there are none then we set the field to (None). If we have just one
@@ -700,8 +701,9 @@ update_table_chooser_from_database()
sql_form = "SELECT n.nspname, c.relname, a.attname FROM pg_class c, pg_namespace n, pg_attribute a WHERE c.relnamespace = n.oid AND n.nspname = '%s' AND c.relname = '%s' AND a.attrelid = c.oid AND a.atttypid IN (SELECT oid FROM pg_type WHERE typname in ('geometry', 'geography'))";
- geocol_query = malloc(strlen(sql_form) + strlen(schema) + strlen(table) + 1);
- sprintf(geocol_query, sql_form, schema, table);
+ sz = strlen(sql_form) + strlen(schema) + strlen(table) + 1;
+ geocol_query = malloc(sz);
+ snprintf(geocol_query, sz, sql_form, schema, table);
geocol_result = PQexec(pg_connection, geocol_query);
@@ -1462,14 +1464,16 @@ pgui_action_import(GtkWidget *widget, gpointer data)
/* Validation: we loop through each of the files in order to validate them as a separate pass */
while (is_valid)
{
+ size_t sz;
/* Grab the SHPLOADERCONFIG for this row */
gtk_tree_model_get(GTK_TREE_MODEL(import_file_list_store), &iter, IMPORT_POINTER_COLUMN, &gptr, -1);
loader_file_config = (SHPLOADERCONFIG *)gptr;
/* For each entry, we execute a remote query in order to determine the column names
and types for the remote table if they actually exist */
- query = malloc(strlen(sql_form) + strlen(loader_file_config->schema) + strlen(loader_file_config->table) + 1);
- sprintf(query, sql_form, loader_file_config->table, loader_file_config->schema);
+ sz = strlen(sql_form) + strlen(loader_file_config->schema) + strlen(loader_file_config->table) + 1;
+ query = malloc(sz);
+ snprintf(query, sz, sql_form, loader_file_config->table, loader_file_config->schema);
result = PQexec(pg_connection, query);
/* Call the validation function with the SHPLOADERCONFIG and the result set */
diff --git a/postgis/gserialized_estimate.c b/postgis/gserialized_estimate.c
index eee95e0f4..d05690e0b 100644
--- a/postgis/gserialized_estimate.c
+++ b/postgis/gserialized_estimate.c
@@ -2321,6 +2321,7 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
GBOX *gbox = NULL;
bool only_parent = false;
int key_type;
+ size_t sz;
/* We need to initialize the internal cache to access it later via postgis_oid() */
postgis_initialize_cache();
@@ -2331,8 +2332,9 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
col = PG_GETARG_TEXT_P(2);
only_parent = PG_GETARG_BOOL(3);
- nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
- sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
+ sz = strlen(nsp) + strlen(tbl) + 6;
+ nsp_tbl = palloc(sz);
+ snprintf(nsp_tbl, sz, "\"%s\".\"%s\"", nsp, tbl);
tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
pfree(nsp_tbl);
}
@@ -2341,8 +2343,9 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
nsp = text_to_cstring(PG_GETARG_TEXT_P(0));
tbl = text_to_cstring(PG_GETARG_TEXT_P(1));
col = PG_GETARG_TEXT_P(2);
- nsp_tbl = palloc(strlen(nsp) + strlen(tbl) + 6);
- sprintf(nsp_tbl, "\"%s\".\"%s\"", nsp, tbl);
+ sz = strlen(nsp) + strlen(tbl) + 6;
+ nsp_tbl = palloc(sz);
+ snprintf(nsp_tbl, sz, "\"%s\".\"%s\"", nsp, tbl);
tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
pfree(nsp_tbl);
}
@@ -2350,8 +2353,9 @@ Datum gserialized_estimated_extent(PG_FUNCTION_ARGS)
{
tbl = text_to_cstring(PG_GETARG_TEXT_P(0));
col = PG_GETARG_TEXT_P(1);
- nsp_tbl = palloc(strlen(tbl) + 3);
- sprintf(nsp_tbl, "\"%s\"", tbl);
+ sz = strlen(tbl) + 3;
+ nsp_tbl = palloc(sz);
+ snprintf(nsp_tbl, sz, "\"%s\"", tbl);
tbl_oid = DatumGetObjectId(DirectFunctionCall1(regclassin, CStringGetDatum(nsp_tbl)));
pfree(nsp_tbl);
}
diff --git a/postgis/gserialized_typmod.c b/postgis/gserialized_typmod.c
index aae44bef5..6d1a84be5 100644
--- a/postgis/gserialized_typmod.c
+++ b/postgis/gserialized_typmod.c
@@ -61,8 +61,8 @@ Datum geometry_enforce_typmod(PG_FUNCTION_ARGS);
PG_FUNCTION_INFO_V1(postgis_typmod_out);
Datum postgis_typmod_out(PG_FUNCTION_ARGS)
{
- char *s = (char*)palloc(64);
- char *str = s;
+ StringInfoData si;
+ // char *s = (char*)palloc(64);
int32 typmod = PG_GETARG_INT32(0);
int32 srid = TYPMOD_GET_SRID(typmod);
int32 type = TYPMOD_GET_TYPE(typmod);
@@ -74,33 +74,32 @@ Datum postgis_typmod_out(PG_FUNCTION_ARGS)
/* No SRID or type or dimensionality? Then no typmod at all. Return empty string. */
if (!(srid || type || hasz || hasm) || typmod < 0)
{
- *str = '\0';
- PG_RETURN_CSTRING(str);
+ PG_RETURN_CSTRING(pstrdup(""));
}
/* Opening bracket. */
- str += sprintf(str, "(");
+ initStringInfo(&si);
+ appendStringInfoChar(&si, '(');
/* Has type? */
if (type)
- str += sprintf(str, "%s", lwtype_name(type));
+ appendStringInfo(&si, "%s", lwtype_name(type));
else if (srid || hasz || hasm)
- str += sprintf(str, "Geometry");
+ appendStringInfoString(&si, "Geometry");
/* Has Z? */
- if (hasz) str += sprintf(str, "%s", "Z");
+ if (hasz) appendStringInfoString(&si, "Z");
/* Has M? */
- if (hasm) str += sprintf(str, "%s", "M");
+ if (hasm) appendStringInfoString(&si, "M");
/* Has SRID? */
- if (srid) str += sprintf(str, ",%d", srid);
+ if (srid) appendStringInfo(&si, ",%d", srid);
/* Closing bracket. */
- str += sprintf(str, ")");
-
- PG_RETURN_CSTRING(s);
+ appendStringInfoChar(&si, ')');
+ PG_RETURN_CSTRING(si.data);
}
diff --git a/postgis/lwgeom_spheroid.c b/postgis/lwgeom_spheroid.c
index fd96bc495..9745ef057 100644
--- a/postgis/lwgeom_spheroid.c
+++ b/postgis/lwgeom_spheroid.c
@@ -122,10 +122,10 @@ Datum ellipsoid_out(PG_FUNCTION_ARGS)
{
SPHEROID *sphere = (SPHEROID *) PG_GETARG_POINTER(0);
char *result;
+ size_t sz = MAX_DIGS_DOUBLE + MAX_DIGS_DOUBLE + 20 + 9 + 2;
+ result = palloc(sz);
- result = palloc(MAX_DIGS_DOUBLE + MAX_DIGS_DOUBLE + 20 + 9 + 2);
-
- sprintf(result,"SPHEROID(\"%s\",%.15g,%.15g)",
+ snprintf(result, sz, "SPHEROID(\"%s\",%.15g,%.15g)",
sphere->name, sphere->a, 1.0/sphere->f);
PG_RETURN_CSTRING(result);
diff --git a/raster/rt_core/rt_geometry.c b/raster/rt_core/rt_geometry.c
index b33452ad3..39aee584e 100644
--- a/raster/rt_core/rt_geometry.c
+++ b/raster/rt_core/rt_geometry.c
@@ -1166,8 +1166,9 @@ rt_raster_gdal_polygonize(
* Thanks to David Zwarg.
**/
if (iBandHasNodataValue) {
- pszQuery = (char *) rtalloc(50 * sizeof (char));
- sprintf(pszQuery, "PixelValue != %f", dBandNoData );
+ size_t sz = 50 * sizeof (char);
+ pszQuery = (char *) rtalloc(sz);
+ snprintf(pszQuery, sz, "PixelValue != %f", dBandNoData );
OGRErr e = OGR_L_SetAttributeFilter(hLayer, pszQuery);
if (e != OGRERR_NONE) {
rtwarn("Error filtering NODATA values for band. All values will be treated as data values");
diff --git a/raster/rt_pg/rtpg_utility.c b/raster/rt_pg/rtpg_utility.c
index 4e1e920fd..d0293e746 100644
--- a/raster/rt_pg/rtpg_utility.c
+++ b/raster/rt_pg/rtpg_utility.c
@@ -77,11 +77,12 @@ Datum RASTER_gdal_version(PG_FUNCTION_ARGS)
/* add indicator if GDAL isn't configured right */
if (!rt_util_gdal_configured()) {
char *rtn = NULL;
- rtn = palloc(strlen(ver) + strlen(" GDAL_DATA not found") + 1);
+ size_t sz = strlen(ver) + strlen(" GDAL_DATA not found") + 1;
+ rtn = palloc(sz);
if (!rtn)
result = cstring_to_text(ver);
else {
- sprintf(rtn, "%s GDAL_DATA not found", ver);
+ snprintf(rtn, sz, "%s GDAL_DATA not found", ver);
result = cstring_to_text(rtn);
pfree(rtn);
}
diff --git a/raster/rt_pg/rtpostgis.c b/raster/rt_pg/rtpostgis.c
index e9a19da4d..08d9955df 100644
--- a/raster/rt_pg/rtpostgis.c
+++ b/raster/rt_pg/rtpostgis.c
@@ -657,10 +657,9 @@ _PG_init(void) {
*/
env_postgis_gdal_enabled_drivers = getenv("POSTGIS_GDAL_ENABLED_DRIVERS");
if (env_postgis_gdal_enabled_drivers == NULL) {
- boot_postgis_gdal_enabled_drivers = palloc(
- sizeof(char) * (strlen(GDAL_DISABLE_ALL) + 1)
- );
- sprintf(boot_postgis_gdal_enabled_drivers, "%s", GDAL_DISABLE_ALL);
+ size_t sz = sizeof(char) * (strlen(GDAL_DISABLE_ALL) + 1);
+ boot_postgis_gdal_enabled_drivers = palloc(sz);
+ snprintf(boot_postgis_gdal_enabled_drivers, sz, "%s", GDAL_DISABLE_ALL);
}
else {
boot_postgis_gdal_enabled_drivers = rtpg_trim(
-----------------------------------------------------------------------
Summary of changes:
extras/wkb_reader/readwkb.c | 2 +-
liblwgeom/lwgeom_debug.c | 18 ++++++++++--------
liblwgeom/lwprint.c | 12 +++++++-----
loader/shp2pgsql-gui.c | 12 ++++++++----
postgis/gserialized_estimate.c | 16 ++++++++++------
postgis/gserialized_typmod.c | 25 ++++++++++++-------------
postgis/lwgeom_spheroid.c | 6 +++---
raster/rt_core/rt_geometry.c | 5 +++--
raster/rt_pg/rtpg_utility.c | 5 +++--
raster/rt_pg/rtpostgis.c | 7 +++----
10 files changed, 60 insertions(+), 48 deletions(-)
hooks/post-receive
--
PostGIS
More information about the postgis-tickets
mailing list