X-Git-Url: https://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fidtree%2Fidtree.c;fp=ccan%2Fidtree%2Fidtree.c;h=bc7ba5fc5e00e6a104961cb0dee217cf618c5fce;hp=bf83c31856e8a6bdea8d8f4040b347c990ecbb99;hb=6994f3d0b1fefa78443253b6b9bf4db15f29b3f3;hpb=d208258f51ac8c3b355cd31a874dcf93099b3e98 diff --git a/ccan/idtree/idtree.c b/ccan/idtree/idtree.c index bf83c318..bc7ba5fc 100644 --- a/ccan/idtree/idtree.c +++ b/ccan/idtree/idtree.c @@ -236,7 +236,7 @@ build_up: static int sub_remove(struct idtree *idp, int shift, int id) { struct idtree_layer *p = idp->top; - struct idtree_layer **pa[MAX_LEVEL]; + struct idtree_layer **pa[1+MAX_LEVEL]; struct idtree_layer ***paa = &pa[0]; int n; @@ -276,7 +276,8 @@ void *idtree_lookup(const struct idtree *idp, int id) * This tests to see if bits outside the current tree are * present. If so, tain't one of ours! */ - if ((id & ~(~0 << MAX_ID_SHIFT)) >> (n + IDTREE_BITS)) + if (n + IDTREE_BITS < 31 && + (id & ~(~0 << MAX_ID_SHIFT)) >> (n + IDTREE_BITS)) return NULL; /* Mask off upper bits we don't use for the search. */