[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH 2/2] pc-dimm: fix large address sorting during auto-
From: |
Igor Mammedov |
Subject: |
[Qemu-devel] [PATCH 2/2] pc-dimm: fix large address sorting during auto-allocation |
Date: |
Mon, 9 Jun 2014 19:28:01 +0200 |
GCompareFunc(a, b) used by g_slist_insert_sorted() return 'gint',
however it might be too small to fit difference between
2 addresses. So use 128bit calculate difference and normalize
result to -1/0/1 return values.
Reported-By: Andrey Korolyov <address@hidden>
Signed-off-by: Igor Mammedov <address@hidden>
---
hw/mem/pc-dimm.c | 8 +++++++-
1 file changed, 7 insertions(+), 1 deletion(-)
diff --git a/hw/mem/pc-dimm.c b/hw/mem/pc-dimm.c
index 9f091c6..8c26568 100644
--- a/hw/mem/pc-dimm.c
+++ b/hw/mem/pc-dimm.c
@@ -73,8 +73,14 @@ static gint pc_dimm_addr_sort(gconstpointer a, gconstpointer
b)
{
PCDIMMDevice *x = PC_DIMM(a);
PCDIMMDevice *y = PC_DIMM(b);
+ Int128 diff = int128_sub(int128_make64(x->addr), int128_make64(y->addr));
- return x->addr - y->addr;
+ if (int128_lt(diff, int128_zero())) {
+ return -1;
+ } else if (int128_gt(diff, int128_zero())) {
+ return 1;
+ }
+ return 0;
}
static int pc_dimm_built_list(Object *obj, void *opaque)
--
1.9.3