Skip to content

Commit

Permalink
array size of zero is an extension
Browse files Browse the repository at this point in the history
  • Loading branch information
alandekok committed Oct 30, 2016
1 parent e4b9624 commit 38788ce
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/util/atomic_queue.c
Expand Up @@ -56,7 +56,7 @@ struct fr_atomic_queue_t {

int size;

fr_atomic_queue_entry_t entry[0];
fr_atomic_queue_entry_t entry[1];
};

/** Create fixed-size atomic queue.
Expand All @@ -73,14 +73,16 @@ fr_atomic_queue_t *fr_atomic_queue_create(TALLOC_CTX *ctx, int size)
int64_t seq;
fr_atomic_queue_t *aq;

if (!size) return NULL;

/*
* Allocate a contiguous blob for the header and queue.
* This helps with memory locality.
*
* Since we're allocating a blob, we should also set the
* name of the data, too.
*/
aq = talloc_size(ctx, sizeof(*aq) + size * sizeof(aq->entry[0]));
aq = talloc_size(ctx, sizeof(*aq) + (size - 1) * sizeof(aq->entry[0]));
if (!aq) return NULL;

talloc_set_name(aq, "fr_atomic_queue_t");
Expand Down

0 comments on commit 38788ce

Please sign in to comment.