summaryrefslogtreecommitdiff
path: root/src/lib/bitmap.c
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-05-08 16:34:19 +0200
committerSander Vrijders <[email protected]>2016-05-08 16:34:19 +0200
commit5812dfb832e513dc455a0d48624bcad62334d457 (patch)
tree93a02e1b20f54bb869eadc856f201412c633315c /src/lib/bitmap.c
parentde8f2015cbd015b1cced366cb12c054be62c23b1 (diff)
parent021af9e01ce6c6376534b33ef1a06ea4189028d4 (diff)
downloadouroboros-5812dfb832e513dc455a0d48624bcad62334d457.tar.gz
ouroboros-5812dfb832e513dc455a0d48624bcad62334d457.zip
Merged in dstaesse/ouroboros/be-fast-path (pull request #65)
irmd: flow allocation and fast path
Diffstat (limited to 'src/lib/bitmap.c')
-rw-r--r--src/lib/bitmap.c19
1 files changed, 11 insertions, 8 deletions
diff --git a/src/lib/bitmap.c b/src/lib/bitmap.c
index 8aabb4f4..e84145b2 100644
--- a/src/lib/bitmap.c
+++ b/src/lib/bitmap.c
@@ -108,12 +108,14 @@ struct bmp * bmp_create(size_t bits, ssize_t offset)
return NULL;
tmp = malloc(sizeof(*tmp));
- if (!tmp)
+ if (tmp == NULL)
return NULL;
- tmp->bitmap = malloc(BITS_TO_LONGS(bits) * sizeof(*(tmp->bitmap)));
- if (!tmp->bitmap)
+ tmp->bitmap = malloc(BITS_TO_LONGS(bits) * sizeof(unsigned long));
+ if (tmp->bitmap == NULL) {
+ free(tmp);
return NULL;
+ }
tmp->size = bits;
tmp->offset = offset;
@@ -140,7 +142,8 @@ int bmp_destroy(struct bmp * b)
static ssize_t bad_id(struct bmp * b)
{
- assert(b);
+ if (b == NULL)
+ return -1;
return b->offset - 1;
}
@@ -149,8 +152,8 @@ ssize_t bmp_allocate(struct bmp * b)
{
ssize_t id;
- if (!b)
- return bad_id(b);
+ if (b == NULL)
+ return -1;
id = (ssize_t) find_next_zero_bit(b->bitmap,
b->size);
@@ -177,7 +180,7 @@ static bool is_id_valid(struct bmp * b,
bool bmp_is_id_valid(struct bmp * b,
ssize_t id)
{
- if (!b)
+ if (b == NULL)
return false;
return is_id_valid(b, id);
@@ -188,7 +191,7 @@ int bmp_release(struct bmp * b,
{
ssize_t rid;
- if (!b)
+ if (b == NULL)
return -1;
if (!is_id_valid(b, id))