[GRASS-SVN] r70964 - grass-addons/grass7/raster/r.pi/r.pi.enn.pr

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Apr 26 23:50:59 PDT 2017


Author: mmetz
Date: 2017-04-26 23:50:59 -0700 (Wed, 26 Apr 2017)
New Revision: 70964

Modified:
   grass-addons/grass7/raster/r.pi/r.pi.enn.pr/main.c
Log:
r.pi.enn.pr: do not silently overwrite, fix segmentation fault

Modified: grass-addons/grass7/raster/r.pi/r.pi.enn.pr/main.c
===================================================================
--- grass-addons/grass7/raster/r.pi/r.pi.enn.pr/main.c	2017-04-27 06:50:00 UTC (rev 70963)
+++ grass-addons/grass7/raster/r.pi/r.pi.enn.pr/main.c	2017-04-27 06:50:59 UTC (rev 70964)
@@ -226,6 +226,7 @@
     /* allocate the cell buffers */
     cells = (Coords *) G_malloc(nrows * ncols * sizeof(Coords));
     fragments = (Coords **) G_malloc(nrows * ncols * sizeof(Coords *));
+    fragments[0] = cells;
     flagbuf = (int *)G_malloc(nrows * ncols * sizeof(int));
     result = Rast_allocate_d_buf();
 
@@ -239,6 +240,7 @@
     }
     Rast_close(in_fd);
 
+    /* find fragments */
     fragcount = writeFragments(fragments, flagbuf, nrows, ncols, neighb_count);
 
     /* perform actual function on the patches */
@@ -248,6 +250,9 @@
     /* open new cellfile  */
     strcpy(outname, newname);
     strcat(outname, ".diff");
+    if (module->overwrite == 0 && G_find_raster(outname, G_mapset()) != NULL)
+	G_fatal_error(_("Output raster <%s> exists. To overwrite, use the --overwrite flag"),
+		      outname);
     out_fd = Rast_open_new(outname, map_type);
     if (out_fd < 0)
 	G_fatal_error(_("Cannot create raster map <%s>"), newname);
@@ -271,6 +276,9 @@
     /* open new cellfile  */
     strcpy(outname, newname);
     strcat(outname, ".PP");
+    if (module->overwrite == 0 && G_find_raster(outname, G_mapset()) != NULL)
+	G_fatal_error(_("Output raster <%s> exists. To overwrite, use the --overwrite flag"),
+		      outname);
     out_fd = Rast_open_new(outname, map_type);
     if (out_fd < 0)
 	G_fatal_error(_("Cannot create raster map <%s>"), newname);
@@ -294,6 +302,9 @@
     /* open new cellfile  */
     strcpy(outname, newname);
     strcat(outname, ".PA");
+    if (module->overwrite == 0 && G_find_raster(outname, G_mapset()) != NULL)
+	G_fatal_error(_("Output raster <%s> exists. To overwrite, use the --overwrite flag"),
+		      outname);
     out_fd = Rast_open_new(outname, map_type);
     if (out_fd < 0)
 	G_fatal_error(_("Cannot create raster map <%s>"), outname);



More information about the grass-commit mailing list