efl - fix many bounds over/underflow where we use int for ptr cmp
authorCarsten Haitzler (Rasterman) <raster@rasterman.com>
Thu, 26 May 2016 03:17:07 +0000 (12:17 +0900)
committerCarsten Haitzler (Rasterman) <raster@rasterman.com>
Thu, 26 May 2016 03:17:07 +0000 (12:17 +0900)
this addresses more things brought up in comments in

fixes T3638 commentd

@fix

src/lib/eina/eina_file_common.c
src/lib/eina/eina_hash.c
src/lib/eina/eina_quadtree.c

index 8314f00..317a421 100644 (file)
@@ -153,8 +153,15 @@ int
 eina_file_map_key_cmp(const unsigned long long int *key1, int key1_length EINA_UNUSED,
                        const unsigned long long int *key2, int key2_length EINA_UNUSED)
 {
-   if (key1[0] - key2[0] == 0) return key1[1] - key2[1];
-   return key1[0] - key2[0];
+   if (key1[0] == key2[0])
+     {
+        if (key1[1] == key2[1]) return 0;
+        if (key1[1] > key2[1]) return 1;
+        return -1;
+     }
+   if (key1[0] == key2[0]) return 0;
+   if (key1[0] > key2[0]) return 1;
+   return -1;
 }
 
 int
index ed155e5..b2d338d 100644 (file)
@@ -536,20 +536,24 @@ static int
 _eina_int32_key_cmp(const uint32_t *key1, EINA_UNUSED int key1_length,
                     const uint32_t *key2, EINA_UNUSED int key2_length)
 {
-   return *key1 - *key2;
+   if (*key1 == *key2) return 0;
+   if (*key1 > *key2) return 1;
+   return -1;
 }
 
 static unsigned int
-_eina_int64_key_length(EINA_UNUSED const uint32_t *key)
+_eina_int64_key_length(EINA_UNUSED const uint64_t *key)
 {
-   return 8;
+   return sizeof(int64_t);
 }
 
 static int
 _eina_int64_key_cmp(const uint64_t *key1, EINA_UNUSED int key1_length,
                     const uint64_t *key2, EINA_UNUSED int key2_length)
 {
-   return *key1 - *key2;
+   if (*key1 == *key2) return 0;
+   if (*key1 > *key2) return 1;
+   return -1;
 }
 
 static Eina_Bool
index e163e6f..246def7 100644 (file)
@@ -167,7 +167,9 @@ _eina_quadtree_item_cmp(const void *a, const void *b)
    const Eina_QuadTree_Item *i = a;
    const Eina_QuadTree_Item *j = b;
 
-   return i->index - j->index;
+   if (i->index == j->index) return 0;
+   if (i->index > j->index) return 1;
+   return -1;
 }
 
 static Eina_QuadTree_Root *