[coreboot-gerrit] Change in coreboot[master]: util/cbmem: Fix compare function for qsort

Furquan Shaikh (Code Review) gerrit at coreboot.org
Fri May 18 00:10:35 CEST 2018


Furquan Shaikh has uploaded this change for review. ( https://review.coreboot.org/26357


Change subject: util/cbmem: Fix compare function for qsort
......................................................................

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 at google.com>
---
M util/cbmem/cbmem.c
1 file changed, 5 insertions(+), 1 deletion(-)



  git pull ssh://review.coreboot.org:29418/coreboot refs/changes/57/26357/1

diff --git a/util/cbmem/cbmem.c b/util/cbmem/cbmem.c
index 21da71b..60a3d1d 100644
--- a/util/cbmem/cbmem.c
+++ b/util/cbmem/cbmem.c
@@ -589,7 +589,11 @@
 	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 */

-- 
To view, visit https://review.coreboot.org/26357
To unsubscribe, or for help writing mail filters, visit https://review.coreboot.org/settings

Gerrit-Project: coreboot
Gerrit-Branch: master
Gerrit-MessageType: newchange
Gerrit-Change-Id: I67c3c4d1761715ecbf259935fabb22ce37c3966e
Gerrit-Change-Number: 26357
Gerrit-PatchSet: 1
Gerrit-Owner: Furquan Shaikh <furquan at google.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.coreboot.org/pipermail/coreboot-gerrit/attachments/20180517/fa527e9c/attachment.html>


More information about the coreboot-gerrit mailing list