From 22d98b7689f9380b02e41d0eb46984c493a7acd5 Mon Sep 17 00:00:00 2001
From: "Peter W. Draper" <p.w.draper@durham.ac.uk>
Date: Tue, 17 Sep 2019 13:55:14 +0100
Subject: [PATCH] dt of ticks might overflow int

---
 mpistalls.c | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/mpistalls.c b/mpistalls.c
index 9df9c4f..2506f51 100644
--- a/mpistalls.c
+++ b/mpistalls.c
@@ -153,7 +153,13 @@ static void *recv_thread(void *arg) {
 static int cmp_logs(const void *p1, const void *p2) {
   struct mpiuse_log_entry *l1 = *(struct mpiuse_log_entry **)p1;
   struct mpiuse_log_entry *l2 = *(struct mpiuse_log_entry **)p2;
-  return l1->tic - l2->tic;
+
+  /* Large unsigned values, so take care. */
+  if (l1->tic > l2->tic)
+    return 1;
+  if (l1->tic < l2->tic)
+    return -1;
+  return 0;
 }
 
 /* Pick out the relevant logging data for our rank, i.e. all activations of
-- 
GitLab