]> www.infradead.org Git - users/dhowells/kafs-utils.git/commitdiff
rxgen: The abort table comparator needs to handle big numbers
authorDavid Howells <dhowells@redhat.com>
Mon, 14 Apr 2014 07:09:58 +0000 (08:09 +0100)
committerDavid Howells <dhowells@redhat.com>
Mon, 14 Apr 2014 07:09:58 +0000 (08:09 +0100)
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>
py_rxgen.c

index 6a261d290f39ba325c398ee7fadf2af93365f916..6c90004c2072e75529a626705cb8913906ea0cc9 100644 (file)
@@ -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;
 }
 
 /*