]> git.ozlabs.org Git - ccan/commitdiff
idtree: Fix undefined behaviour (left shift of signed value)
authorDavid Gibson <david@gibson.dropbear.id.au>
Wed, 27 Jan 2016 13:17:47 +0000 (00:17 +1100)
committerDavid Gibson <david@gibson.dropbear.id.au>
Tue, 2 Feb 2016 12:00:06 +0000 (23:00 +1100)
~0 will be signed and negative on any 2s complement system, and
left shifting a negative value has undefined behaviour in C.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
ccan/idtree/idtree.c

index 5bd8882220868d02d4d172ded3967643f6507b17..6e75450e67e85af287a9967cd7e88af66e147a5b 100644 (file)
@@ -278,7 +278,7 @@ void *idtree_lookup(const struct idtree *idp, int id)
         * present.  If so, tain't one of ours!
         */
        if (n + IDTREE_BITS < 31 &&
-           (id & ~(~0 << MAX_ID_SHIFT)) >> (n + IDTREE_BITS))
+           (id & ~(~0U << MAX_ID_SHIFT)) >> (n + IDTREE_BITS))
             return NULL;
 
        /* Mask off upper bits we don't use for the search. */