From: David Howells Date: Mon, 14 Apr 2014 07:09:58 +0000 (+0100) Subject: rxgen: The abort table comparator needs to handle big numbers X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=abaecb45e3c0366ba047ebbb7c06f6c69a354bf6;p=users%2Fdhowells%2Fkafs-utils.git 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 --- 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; } /*