[GRASS-SVN] r30327 - grass/trunk/raster/r.mapcalc

svn_grass at osgeo.org svn_grass at osgeo.org
Sun Feb 24 12:30:36 EST 2008


Author: glynn
Date: 2008-02-24 12:30:36 -0500 (Sun, 24 Feb 2008)
New Revision: 30327

Modified:
   grass/trunk/raster/r.mapcalc/xrand.c
Log:
Fix integer wrap-around in rand() function



Modified: grass/trunk/raster/r.mapcalc/xrand.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xrand.c	2008-02-24 15:53:45 UTC (rev 30326)
+++ grass/trunk/raster/r.mapcalc/xrand.c	2008-02-24 17:30:36 UTC (rev 30327)
@@ -13,7 +13,7 @@
 
 #if !defined(HAVE_DRAND48)
 #define drand48() ((double)rand()/((double)RAND_MAX + 1))
-#define lrand48() ((long)rand())
+#define mrand48() ((long)rand())
 #endif
 
 int 
@@ -35,11 +35,11 @@
 		CELL *arg2 = args[2];
 		for (i = 0; i < columns; i++)
 		{
-			long x = lrand48();
+			unsigned long x = (unsigned long) mrand48();
 			int lo = arg1[i];
 			int hi = arg2[i];
 			if (lo > hi) { int tmp = lo; lo = hi; hi = tmp; }
-			res[i] = (lo == hi) ? lo : lo + x % (hi - lo);
+			res[i] = (lo == hi) ? lo : lo + x % (unsigned long) (hi - lo);
 		}
 		return 0;
 	}



More information about the grass-commit mailing list