[GRASS-SVN] r56285 - grass/trunk/raster/r.mapcalc
svn_grass at osgeo.org
svn_grass at osgeo.org
Fri May 17 07:45:18 PDT 2013
Author: glynn
Date: 2013-05-17 07:45:18 -0700 (Fri, 17 May 2013)
New Revision: 56285
Modified:
grass/trunk/raster/r.mapcalc/xmod.c
Log:
Fix potential integer overflow in modulo function
Modified: grass/trunk/raster/r.mapcalc/xmod.c
===================================================================
--- grass/trunk/raster/r.mapcalc/xmod.c 2013-05-17 12:44:56 UTC (rev 56284)
+++ grass/trunk/raster/r.mapcalc/xmod.c 2013-05-17 14:45:18 UTC (rev 56285)
@@ -1,4 +1,6 @@
+#include <math.h>
+
#include <grass/gis.h>
#include <grass/raster.h>
#include "globals.h"
@@ -46,14 +48,10 @@
if (IS_NULL_F(&arg1[i]) || IS_NULL_F(&arg2[i]))
SET_NULL_F(&res[i]);
else {
- int k;
-
floating_point_exception = 0;
- k = (int)(arg1[i] / arg2[i]);
+ res[i] = (FCELL) fmod(arg1[i], arg2[i]);
if (floating_point_exception)
SET_NULL_F(&res[i]);
- else
- res[i] = arg1[i] - k * arg2[i];
}
}
return 0;
@@ -68,14 +66,10 @@
if (IS_NULL_D(&arg1[i]) || IS_NULL_D(&arg2[i]))
SET_NULL_D(&res[i]);
else {
- int k;
-
floating_point_exception = 0;
- k = (int)(arg1[i] / arg2[i]);
+ res[i] = (DCELL) fmod(arg1[i], arg2[i]);
if (floating_point_exception)
SET_NULL_D(&res[i]);
- else
- res[i] = arg1[i] - k * arg2[i];
}
}
return 0;
More information about the grass-commit
mailing list