From 8f567320ba85f1cddbb6770b1033961c3d7486ff Mon Sep 17 00:00:00 2001
From: Furquan Shaikh <furquan@google.com>
Date: Thu, 17 May 2018 15:08:03 -0700
Subject: util/cbmem: Fix compare function for qsort

compare_timestamp_entries will fail for entries that are different by
at least 2^32 since entry_stamp is 64-bit and the return for compare
is 32-bit. This change fixes compare_timestamps by actually comparing
the entries to return 1, -1 or 0 instead of doing math on them.

TEST=Verified that "cbmem -t" sorts entries correctly on previously
failing entries.

Change-Id: I67c3c4d1761715ecbf259935fabb22ce37c3966e
Signed-off-by: Furquan Shaikh <furquan@google.com>
Reviewed-on: https://review.coreboot.org/26357
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
---
 util/cbmem/cbmem.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

(limited to 'util')

diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index 21da71b24f..42761dc846 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -589,7 +589,12 @@ static int compare_timestamp_entries(const void *a, const void *b)
 	const struct timestamp_entry *tse_a = (struct timestamp_entry *)a;
 	const struct timestamp_entry *tse_b = (struct timestamp_entry *)b;
 
-	return tse_a->entry_stamp - tse_b->entry_stamp;
+	if (tse_a->entry_stamp > tse_b->entry_stamp)
+		return 1;
+	else if (tse_a->entry_stamp < tse_b->entry_stamp)
+		return -1;
+
+	return 0;
 }
 
 /* dump the timestamp table */
-- 
cgit v1.2.3