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