Blame SOURCES/0089-utils-boot-analysis-Avoid-overflow-when-comparing-la.patch

e76f14
From 832609cc5f16a955648880ebc69b8f226f8782bb Mon Sep 17 00:00:00 2001
e76f14
From: "Richard W.M. Jones" <rjones@redhat.com>
e76f14
Date: Sat, 14 May 2016 19:22:49 +0100
e76f14
Subject: [PATCH] utils: boot-analysis: Avoid overflow when comparing large
e76f14
 doubles.
e76f14
e76f14
(cherry picked from commit 1f4a0bd90df35df56eb86c2386d801b51828cb22)
e76f14
---
e76f14
 utils/boot-analysis/boot-analysis.c | 11 ++++++++++-
e76f14
 1 file changed, 10 insertions(+), 1 deletion(-)
e76f14
e76f14
diff --git a/utils/boot-analysis/boot-analysis.c b/utils/boot-analysis/boot-analysis.c
e76f14
index 3690ed4..d06d9a1 100644
e76f14
--- a/utils/boot-analysis/boot-analysis.c
e76f14
+++ b/utils/boot-analysis/boot-analysis.c
e76f14
@@ -1157,7 +1157,16 @@ compare_activities_pointers_by_mean (const void *av, const void *bv)
e76f14
 
e76f14
   assert ((*a)->magic == ACTIVITY_MAGIC);
e76f14
   assert ((*b)->magic == ACTIVITY_MAGIC);
e76f14
-  return (*b)->mean - (*a)->mean;
e76f14
+
e76f14
+  /* The mean field is a double in nanoseconds.  For the result of the
e76f14
+   * comparison we want an integer.  If it is larger than around 2^32,
e76f14
+   * the following will produce an incorrect result.  Therefore we use
e76f14
+   * this trick.  Note we want to return largest first.
e76f14
+   */
e76f14
+  double a_mean = (*a)->mean;
e76f14
+  double b_mean = (*b)->mean;
e76f14
+
e76f14
+  return (b_mean > a_mean) - (b_mean < a_mean);
e76f14
 }
e76f14
 
e76f14
 static void
e76f14
-- 
e76f14
1.8.3.1
e76f14