[GRASS-SVN] r72268 - in grass/trunk: include lib/raster

svn_grass at osgeo.org svn_grass at osgeo.org
Wed Feb 21 13:14:37 PST 2018


Author: mmetz
Date: 2018-02-21 13:14:37 -0800 (Wed, 21 Feb 2018)
New Revision: 72268

Modified:
   grass/trunk/include/raster.h
   grass/trunk/lib/raster/range.c
Log:
libraster: use grass_int64 for count of non-null cells in R_stats

Modified: grass/trunk/include/raster.h
===================================================================
--- grass/trunk/include/raster.h	2018-02-21 21:13:25 UTC (rev 72267)
+++ grass/trunk/include/raster.h	2018-02-21 21:14:37 UTC (rev 72268)
@@ -219,7 +219,7 @@
 {
     DCELL sum;
     DCELL sumsq;
-    off_t count;
+    grass_int64 count;
 };
 
 struct Range

Modified: grass/trunk/lib/raster/range.c
===================================================================
--- grass/trunk/lib/raster/range.c	2018-02-21 21:13:25 UTC (rev 72267)
+++ grass/trunk/lib/raster/range.c	2018-02-21 21:14:37 UTC (rev 72268)
@@ -269,7 +269,7 @@
     unsigned char cc[8];
     char nbytes;
     int i;
-    off_t count;
+    grass_int64 count;
 
     Rast_init();
     init_rstats(rstats);
@@ -312,7 +312,11 @@
 	return -1;
     }
 
-    if (nbytes < 1 || nbytes > sizeof(off_t)) {
+    count = 0;
+    if (nbytes == 0)
+	return 1;
+
+    if (nbytes < 1 || nbytes > sizeof(grass_int64)) {
 	close(fd);
 	G_debug(1, "Invalid byte count in stats file for <%s>",
 		  G_fully_qualified_name(name, mapset));
@@ -326,7 +330,6 @@
 	return -1;
     }
 
-    count = 0;
     /* copy byte by byte */
     for (i = nbytes - 1; i >= 0; i--) {
 	count = (count << 8);
@@ -437,7 +440,7 @@
     unsigned char cc[8];
     char nbytes;
     int i;
-    off_t count;
+    grass_int64 count;
 
     Rast_init();
 
@@ -465,7 +468,7 @@
     count = rstats->count;
     nbytes = 0;
     /* copy byte by byte */
-    for (i = 0; i < sizeof(off_t); i++) {
+    for (i = 0; i < sizeof(grass_int64); i++) {
 	cc[i] = count & 0xff;
 	count >>= 8;
 	if (cc[i])
@@ -479,7 +482,7 @@
 	G_fatal_error(_("Unable to write stats file for <%s>"), name);
     }
 
-    if (write(fd, cc, nbytes) != nbytes) {
+    if (nbytes > 0 && write(fd, cc, nbytes) != nbytes) {
 	G_remove_misc("cell_misc", "stats", name);
 	G_fatal_error(_("Unable to write stats file for <%s>"), name);
     }



More information about the grass-commit mailing list