X-Git-Url: http://git.ozlabs.org/?p=ccan;a=blobdiff_plain;f=ccan%2Fidtree%2Fidtree.c;h=b3b1d606156a8ab79b2066cdadcfa8c8a34ef674;hp=bf83c31856e8a6bdea8d8f4040b347c990ecbb99;hb=fbae37ba91ec230e34be564084099726cc3a9d47;hpb=184070eb4a4a2e130c0053eb82fd8c96a19e954f diff --git a/ccan/idtree/idtree.c b/ccan/idtree/idtree.c index bf83c318..b3b1d606 100644 --- a/ccan/idtree/idtree.c +++ b/ccan/idtree/idtree.c @@ -99,8 +99,8 @@ static int sub_alloc(struct idtree *idp, const void *ptr, int *starting_id) { int n, m, sh; struct idtree_layer *p, *pn; - struct idtree_layer *pa[MAX_LEVEL]; - int l, id, oid; + struct idtree_layer *pa[MAX_LEVEL+1]; + unsigned int l, id, oid; uint32_t bm; memset(pa, 0, sizeof(pa)); @@ -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. */