lib/util: Simplify bitmap.c a bit
authorVolker Lendecke <vl@samba.org>
Tue, 30 Oct 2012 22:15:09 +0000 (23:15 +0100)
committerMichael Adam <obnox@samba.org>
Wed, 7 Nov 2012 14:32:24 +0000 (15:32 +0100)
This avoids the double-talloc for bitmaps

Signed-off-by: Volker Lendecke <vl@samba.org>
Reviewed-by: Michael Adam <obnox@samba.org>
lib/util/bitmap.c

index 1ae2aaaf710a0c07aeeae8a625b62416fc82bc15..77de55aec7c626b6a665cbab007cf8a8923a5665 100644 (file)
@@ -21,8 +21,8 @@
 #include "lib/util/bitmap.h"
 
 struct bitmap {
-       uint32_t *b;
        unsigned int n;
+       uint32_t b[1];          /* We allocate more */
 };
 
 /* these functions provide a simple way to allocate integers from a
@@ -35,16 +35,15 @@ struct bitmap *bitmap_talloc(TALLOC_CTX *mem_ctx, int n)
 {
        struct bitmap *bm;
 
-       bm = talloc(mem_ctx, struct bitmap);
+       bm = (struct bitmap *)talloc_zero_size(
+               mem_ctx,
+               offsetof(struct bitmap, b) + sizeof(uint32_t)*((n+31)/32));
 
        if (!bm) return NULL;
 
+       talloc_set_name_const(bm, "struct bitmap");
+
        bm->n = n;
-       bm->b = talloc_zero_array(bm, uint32_t, (n+31)/32);
-       if (!bm->b) {
-               TALLOC_FREE(bm);
-               return NULL;
-       }
        return bm;
 }