simotek pushed a commit to branch efl-1.17.

http://git.enlightenment.org/core/efl.git/commit/?id=3dfca46f4672435033788045a80474d48c3c15aa

commit 3dfca46f4672435033788045a80474d48c3c15aa
Author: Carsten Haitzler (Rasterman) <[email protected]>
Date:   Thu May 26 12:17:07 2016 +0900

    efl - fix many bounds over/underflow where we use int for ptr cmp
    
    this addresses more things brought up in comments in
    
    fixes T3638 commentd
    
    @fix
---
 src/lib/eina/eina_file_common.c | 11 +++++++++--
 src/lib/eina/eina_hash.c        | 12 ++++++++----
 src/lib/eina/eina_quadtree.c    |  4 +++-
 3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/src/lib/eina/eina_file_common.c b/src/lib/eina/eina_file_common.c
index 8314f00..317a421 100644
--- a/src/lib/eina/eina_file_common.c
+++ b/src/lib/eina/eina_file_common.c
@@ -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
diff --git a/src/lib/eina/eina_hash.c b/src/lib/eina/eina_hash.c
index ed155e5..b2d338d 100644
--- a/src/lib/eina/eina_hash.c
+++ b/src/lib/eina/eina_hash.c
@@ -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
diff --git a/src/lib/eina/eina_quadtree.c b/src/lib/eina/eina_quadtree.c
index e163e6f..246def7 100644
--- a/src/lib/eina/eina_quadtree.c
+++ b/src/lib/eina/eina_quadtree.c
@@ -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 *

-- 


Reply via email to