[gnome-builder] egg-task-cache: transform 64-bit calculation into 32-bit space



commit c26afbae0c0ba47843ff4f74a320adcb2935ac56
Author: Christian Hergert <christian hergert me>
Date:   Wed May 13 20:20:50 2015 -0700

    egg-task-cache: transform 64-bit calculation into 32-bit space
    
    It's technically unsafe, now matter how unlikely, for us to return the
    64-bit math for the qsort() style compare function. We need to ensure
    we stay within the 32-bit space allotted by gint.

 contrib/egg/egg-task-cache.c |   18 ++++++++++++++++--
 1 files changed, 16 insertions(+), 2 deletions(-)
---
diff --git a/contrib/egg/egg-task-cache.c b/contrib/egg/egg-task-cache.c
index f05b4c6..26e9ed6 100644
--- a/contrib/egg/egg-task-cache.c
+++ b/contrib/egg/egg-task-cache.c
@@ -181,8 +181,22 @@ cache_item_compare_evict_at (gconstpointer a,
 {
   const CacheItem *ci1 = a;
   const CacheItem *ci2 = b;
+  gint64 ret;
 
-  return ci2->evict_at - ci1->evict_at;
+  /*
+   * While unlikely, but since we are working with 64-bit monotonic clock and
+   * 32-bit return values, we can't do the normal (a - b) trick. We need to
+   * ensure we are within the 32-bit boundary.
+   */
+
+  ret = ci2->evict_at - ci1->evict_at;
+
+  if (ret < 0)
+    return -1;
+  else if (ret > 0)
+    return 1;
+  else
+    return 0;
 }
 
 static CacheItem *


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]