Browse Source

v.what.rast(3): prevent integer overflow

git-svn-id: https://svn.osgeo.org/grass/grass/trunk@74198 15284696-431f-4ddb-bdfa-cd5b030d7da7
Markus Metz 6 years ago
parent
commit
a6c457fe8a
2 changed files with 12 additions and 3 deletions
  1. 8 2
      vector/v.what.rast/search.c
  2. 4 1
      vector/v.what.rast3/search.c

+ 8 - 2
vector/v.what.rast/search.c

@@ -5,7 +5,10 @@ int by_row(const void *ii, const void *jj)
 {
     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 @@ int by_cat(const void *ii, const void *jj)
 {
     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 */

+ 4 - 1
vector/v.what.rast3/search.c

@@ -5,7 +5,10 @@ int by_cat(const void *ii, const void *jj)
 {
     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 */