X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Fidtree%2Fidtree.c;h=6e75450e67e85af287a9967cd7e88af66e147a5b;hb=e846b1a93ecf096164ff2c4faaf4a89c24a0e76b;hp=bc7ba5fc5e00e6a104961cb0dee217cf618c5fce;hpb=6994f3d0b1fefa78443253b6b9bf4db15f29b3f3;p=ccan diff --git a/ccan/idtree/idtree.c b/ccan/idtree/idtree.c index bc7ba5fc..6e75450e 100644 --- a/ccan/idtree/idtree.c +++ b/ccan/idtree/idtree.c @@ -25,7 +25,7 @@ */ #include -#include +#include #include #include @@ -87,7 +87,7 @@ static void free_layer(struct idtree *idp, struct idtree_layer *p) static int idtree_pre_get(struct idtree *idp) { while (idp->id_free_cnt < IDTREE_FREE_MAX) { - struct idtree_layer *pn = talloc_zero(idp, struct idtree_layer); + struct idtree_layer *pn = talz(idp, struct idtree_layer); if(pn == NULL) return (0); free_layer(idp, pn); @@ -99,8 +99,9 @@ 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; + int id, oid; uint32_t bm; memset(pa, 0, sizeof(pa)); @@ -134,7 +135,7 @@ restart: */ sh = IDTREE_BITS * (l + 1); if (oid >> sh == id >> sh) - continue; + continue; else goto restart; } @@ -277,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. */ @@ -313,14 +314,14 @@ bool idtree_remove(struct idtree *idp, int id) } while (idp->id_free_cnt >= IDTREE_FREE_MAX) { p = alloc_layer(idp); - talloc_free(p); + tal_free(p); } return true; } struct idtree *idtree_new(void *mem_ctx) { - return talloc_zero(mem_ctx, struct idtree); + return talz(mem_ctx, struct idtree); } int idtree_add(struct idtree *idp, const void *ptr, int limit)