[GRASS-SVN] r73145 - in grass/branches/releasebranch_7_4: general/g.mkfontcap lib/vector/Vlib lib/vector/neta raster/r.distance raster/r.kappa raster/r.stats raster/r.what vector/v.generalize vector/v.overlay vector/v.to.rast vector/v.vect.stats vector/v.what.rast vector/v.what.rast3
svn_grass at osgeo.org
svn_grass at osgeo.org
Thu Aug 23 07:25:45 PDT 2018
Author: mmetz
Date: 2018-08-23 07:25:45 -0700 (Thu, 23 Aug 2018)
New Revision: 73145
Modified:
grass/branches/releasebranch_7_4/general/g.mkfontcap/main.c
grass/branches/releasebranch_7_4/lib/vector/Vlib/break_lines.c
grass/branches/releasebranch_7_4/lib/vector/neta/spanningtree.c
grass/branches/releasebranch_7_4/raster/r.distance/edges.c
grass/branches/releasebranch_7_4/raster/r.kappa/prt_mat.c
grass/branches/releasebranch_7_4/raster/r.stats/stats.c
grass/branches/releasebranch_7_4/raster/r.what/main.c
grass/branches/releasebranch_7_4/vector/v.generalize/misc.c
grass/branches/releasebranch_7_4/vector/v.overlay/area_area.c
grass/branches/releasebranch_7_4/vector/v.to.rast/support.c
grass/branches/releasebranch_7_4/vector/v.vect.stats/main.c
grass/branches/releasebranch_7_4/vector/v.what.rast/search.c
grass/branches/releasebranch_7_4/vector/v.what.rast3/search.c
Log:
bulk backport for #3564 fixing qsort callback fns
Modified: grass/branches/releasebranch_7_4/general/g.mkfontcap/main.c
===================================================================
--- grass/branches/releasebranch_7_4/general/g.mkfontcap/main.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/general/g.mkfontcap/main.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -195,7 +195,7 @@
/* Sort first by type, then by name */
if (aa->type != bb->type)
- return (aa->type > bb->type);
+ return (aa->type > bb->type ? 1 : -1);
else {
const char *na = aa->name;
const char *nb = bb->name;
Modified: grass/branches/releasebranch_7_4/lib/vector/Vlib/break_lines.c
===================================================================
--- grass/branches/releasebranch_7_4/lib/vector/Vlib/break_lines.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/lib/vector/Vlib/break_lines.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -110,7 +110,9 @@
{
int ai = *(int *)a;
int bi = *(int *)b;
-
+
+ /* ai - bi is ok because ai and bi are positive integers
+ * -> no integer overflow */
return (ai - bi);
}
Modified: grass/branches/releasebranch_7_4/lib/vector/neta/spanningtree.c
===================================================================
--- grass/branches/releasebranch_7_4/lib/vector/neta/spanningtree.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/lib/vector/neta/spanningtree.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -73,7 +73,10 @@
static int cmp_edge(const void *pa, const void *pb)
{
- return ((edge_cost_pair *) pa)->cost - ((edge_cost_pair *) pb)->cost;
+ if (((edge_cost_pair *) pa)->cost < ((edge_cost_pair *) pb)->cost)
+ return -1;
+
+ return (((edge_cost_pair *) pa)->cost > ((edge_cost_pair *) pb)->cost);
}
/*!
Modified: grass/branches/releasebranch_7_4/raster/r.distance/edges.c
===================================================================
--- grass/branches/releasebranch_7_4/raster/r.distance/edges.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/raster/r.distance/edges.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -150,7 +150,10 @@
{
const struct CatEdgeList *a = aa, *b = bb;
- return (int)(a->cat - b->cat);
+ if (a->cat < b->cat)
+ return -1;
+
+ return (a->cat > b->cat);
}
void sort_edge_list(struct Map *map)
Modified: grass/branches/releasebranch_7_4/raster/r.kappa/prt_mat.c
===================================================================
--- grass/branches/releasebranch_7_4/raster/r.kappa/prt_mat.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/raster/r.kappa/prt_mat.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -206,5 +206,8 @@
const long *a = aa;
const long *b = bb;
- return (*a - *b);
+ if (*a < *b)
+ return -1;
+
+ return (*a > *b);
}
Modified: grass/branches/releasebranch_7_4/raster/r.stats/stats.c
===================================================================
--- grass/branches/releasebranch_7_4/raster/r.stats/stats.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/raster/r.stats/stats.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -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)
Modified: grass/branches/releasebranch_7_4/raster/r.what/main.c
===================================================================
--- grass/branches/releasebranch_7_4/raster/r.what/main.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/raster/r.what/main.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -562,7 +562,9 @@
{
const struct order *i = ii, *j = jj;
- return i->row - j->row;
+ if (i->row < j->row)
+ return -1;
+ return (i->row > j->row);
}
Modified: grass/branches/releasebranch_7_4/vector/v.generalize/misc.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.generalize/misc.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/vector/v.generalize/misc.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -202,7 +202,10 @@
int ai = *(int *)a;
int bi = *(int *)b;
- return (ai - bi);
+ if (ai < bi)
+ return -1;
+
+ return (ai > bi);
}
/* check topology corruption by boundary modification
Modified: grass/branches/releasebranch_7_4/vector/v.overlay/area_area.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.overlay/area_area.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/vector/v.overlay/area_area.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -18,7 +18,10 @@
/* for ilist qsort'ing and bsearch'ing */
static int cmp_int(const void *a, const void *b)
{
- return (*(int *)a - *(int *)b);
+ if (*(int *)a < *(int *)b)
+ return -1;
+
+ return (*(int *)a > *(int *)b);
}
int area_area(struct Map_info *In, int *field, struct Map_info *Tmp,
Modified: grass/branches/releasebranch_7_4/vector/v.to.rast/support.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.to.rast/support.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/vector/v.to.rast/support.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -226,7 +226,10 @@
struct My_labels_rule *al = (struct My_labels_rule *) a;
struct My_labels_rule *bl = (struct My_labels_rule *) b;
- return (al->i - bl->i);
+ if (al->i < bl->i)
+ return -1;
+
+ return (al->i > bl->i);
}
/* add labels to raster cells */
Modified: grass/branches/releasebranch_7_4/vector/v.vect.stats/main.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.vect.stats/main.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/vector/v.vect.stats/main.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -68,7 +68,10 @@
AREA_CAT *p1 = (AREA_CAT *) pa;
AREA_CAT *p2 = (AREA_CAT *) pb;
- return (p1->area_cat - p2->area_cat);
+ if (p1->area_cat < p2->area_cat)
+ return -1;
+
+ return (p1->area_cat > p2->area_cat);
}
int main(int argc, char *argv[])
Modified: grass/branches/releasebranch_7_4/vector/v.what.rast/search.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.what.rast/search.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/vector/v.what.rast/search.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -5,7 +5,10 @@
{
const struct order *i = ii, *j = jj;
- return i->row - j->row;
+ if (i->row < j->row)
+ return -1;
+
+ return (i->row > j->row);
}
/* for qsort, order list by cat */
@@ -13,7 +16,10 @@
{
const struct order *i = ii, *j = jj;
- return i->cat - j->cat;
+ if (i->cat < j->cat)
+ return -1;
+
+ return (i->cat > j->cat);
}
/* for bsearch, find cat */
Modified: grass/branches/releasebranch_7_4/vector/v.what.rast3/search.c
===================================================================
--- grass/branches/releasebranch_7_4/vector/v.what.rast3/search.c 2018-08-23 14:25:40 UTC (rev 73144)
+++ grass/branches/releasebranch_7_4/vector/v.what.rast3/search.c 2018-08-23 14:25:45 UTC (rev 73145)
@@ -5,7 +5,10 @@
{
const struct order *i = ii, *j = jj;
- return i->cat - j->cat;
+ if (i->cat < j->cat)
+ return -1;
+
+ return (i->cat > j->cat);
}
/* for bsearch, find cat */
More information about the grass-commit
mailing list