From abaecb45e3c0366ba047ebbb7c06f6c69a354bf6 Mon Sep 17 00:00:00 2001 From: David Howells Date: Mon, 14 Apr 2014 08:09:58 +0100 Subject: [PATCH] rxgen: The abort table comparator needs to handle big numbers The abort table comparator needs to handle big numbers (larger than 0x7fffffff). Subtracting a small number from such a big number and then casting to a signed int results in a negative number, which bsearch() interprets as indicating that the bigger number is smaller than the smaller number. Signed-off-by: David Howells --- py_rxgen.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/py_rxgen.c b/py_rxgen.c index 6a261d2..6c90004 100644 --- a/py_rxgen.c +++ b/py_rxgen.c @@ -1037,8 +1037,15 @@ error: static int py_rxgen_received_abort_cmp(const void *key, const void *_entry) { const struct kafs_abort_list *entry = _entry; + int ret; - return (uint32_t)(unsigned long)key - entry->id; + if ((uint32_t)(unsigned long)key > entry->id) + ret = 1; + else if ((uint32_t)(unsigned long)key < entry->id) + ret = -1; + else + ret = 0; + return ret; } /* -- 2.50.1