[GRASS-SVN] r73137 - grass/trunk/raster/r.stats
svn_grass at osgeo.org
svn_grass at osgeo.org
Wed Aug 22 12:41:05 PDT 2018
Author: mmetz
Date: 2018-08-22 12:41:05 -0700 (Wed, 22 Aug 2018)
New Revision: 73137
Modified:
grass/trunk/raster/r.stats/stats.c
Log:
r.stats: fix qsort cmp fn (see #3564)
Modified: grass/trunk/raster/r.stats/stats.c
===================================================================
--- grass/trunk/raster/r.stats/stats.c 2018-08-22 19:38:19 UTC (rev 73136)
+++ grass/trunk/raster/r.stats/stats.c 2018-08-22 19:41:05 UTC (rev 73137)
@@ -183,14 +183,18 @@
static int node_compare(const void *pp, const void *qq)
{
struct Node *const *p = pp, *const *q = qq;
- register int i, x;
+ register int i;
register const CELL *a, *b;
a = (*p)->values;
b = (*q)->values;
- for (i = nfiles; --i >= 0;)
- if (x = (*a++ - *b++), x)
- return x;
+ for (i = nfiles; --i >= 0;) {
+ if (*a < *b)
+ return -1;
+ else if (*a > *b)
+ return 1;
+ a++, b++;
+ }
return 0;
}
@@ -203,7 +207,9 @@
a = (*p)->count;
b = (*q)->count;
- return (a - b);
+ if (a < b)
+ return -1;
+ return (a > b);
}
static int node_compare_count_desc(const void *pp, const void *qq)
@@ -214,7 +220,9 @@
a = (*p)->count;
b = (*q)->count;
- return (b - a);
+ if (a > b)
+ return -1;
+ return (a < b);
}
int sort_cell_stats(int do_sort)
More information about the grass-commit
mailing list