]> granicus.if.org Git - postgis/commitdiff
Explicitly set NULL character to snprintf outputs as Windows does not do so automatic...
authorBborie Park <bkpark at ucdavis.edu>
Tue, 13 Mar 2012 18:06:58 +0000 (18:06 +0000)
committerBborie Park <bkpark at ucdavis.edu>
Tue, 13 Mar 2012 18:06:58 +0000 (18:06 +0000)
git-svn-id: http://svn.osgeo.org/postgis/trunk@9488 b70326c6-7e19-0410-871a-916f4a2858ee

raster/loader/raster2pgsql.c

index 405e201a41b765ae073608c5b97dba053713e71e..f7d2948ce40ecfe3cec78168faf41b32da320705 100644 (file)
@@ -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) {