From 69981669f991699004eb740b38d90e770123549f Mon Sep 17 00:00:00 2001 From: Bborie Park Date: Tue, 13 Mar 2012 18:06:58 +0000 Subject: [PATCH] Explicitly set NULL character to snprintf outputs as Windows does not do so automatically. Ticket is #1682. git-svn-id: http://svn.osgeo.org/postgis/trunk@9488 b70326c6-7e19-0410-871a-916f4a2858ee --- raster/loader/raster2pgsql.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/raster/loader/raster2pgsql.c b/raster/loader/raster2pgsql.c index 405e201a4..f7d2948ce 100644 --- a/raster/loader/raster2pgsql.c +++ b/raster/loader/raster2pgsql.c @@ -2421,22 +2421,25 @@ main(int argc, char **argv) { /* schema.table */ if (ptr) { - config->schema = rtalloc(sizeof(char) * (strlen(config->rt_file[config->rt_file_count - 1]) + 1)); + config->schema = rtalloc(sizeof(char) * (ptr - config->rt_file[config->rt_file_count - 1] + 1)); if (config->schema == NULL) { rterror(_("Could not allocate memory for storing schema name")); rtdealloc_config(config); exit(1); } snprintf(config->schema, ptr - config->rt_file[config->rt_file_count - 1] + 1, "%s", config->rt_file[config->rt_file_count - 1]); + config->schema[ptr - config->rt_file[config->rt_file_count - 1]] = '\0'; - config->table = rtalloc(sizeof(char) * strlen(config->rt_file[config->rt_file_count - 1])); + config->table = rtalloc(sizeof(char) * (strlen(config->rt_file[config->rt_file_count - 1]) - strlen(config->schema) + 1)); if (config->table == NULL) { rterror(_("Could not allocate memory for storing table name")); rtdealloc_config(config); exit(1); } snprintf(config->table, strlen(config->rt_file[config->rt_file_count - 1]) - strlen(config->schema), "%s", ptr + 1); + config->table[strlen(config->rt_file[config->rt_file_count - 1]) - strlen(config->schema)] = '\0'; } + /* table */ else { config->table = rtalloc(sizeof(char) * strlen(config->rt_file[config->rt_file_count - 1]) + 1); if (config->table == NULL) { -- 2.50.1