Browse Source

idtree: Fix undefined behaviour (left shift of signed value)

~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>
David Gibson 10 years ago
parent
commit
36a15d7dee
1 changed files with 1 additions and 1 deletions
  1. 1 1
      ccan/idtree/idtree.c

+ 1 - 1
ccan/idtree/idtree.c

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