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 <dhowells@redhat.com>
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;
}
/*