Skip to content

Commit 1d96700

Browse files
authored
Fix uninitialized active field (#5)
1 parent 91140b2 commit 1d96700

2 files changed

Lines changed: 7 additions & 0 deletions

File tree

src/static_queue.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,18 +33,24 @@ int32_t staticQueueInit(staticQueue_t* queue,
3333
uint32_t node_size,
3434
staticQueueItem_t* first_item)
3535
{
36+
if (queue_size == 0) {
37+
return STATIC_QUEUE_INVALID;
38+
}
39+
3640
queue->head = first_item;
3741
queue->tail = first_item;
3842
queue->first_item = first_item;
3943
queue->queue_length = queue_size;
4044

4145
staticQueueItem_t* item = first_item;
4246
for (uint32_t i = 0; i < queue_size - 1; i++) {
47+
item->active = false;
4348
item->next = (staticQueueItem_t*)((uint8_t*)item + node_size);
4449
item->next->last = item;
4550
item = item->next;
4651
}
4752

53+
item->active = false;
4854
first_item->last = item;
4955
item->next = first_item;
5056

src/static_queue.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@ typedef enum {
8383
STATIC_QUEUE_FULL = -401,
8484
STATIC_QUEUE_EMPTY = -402,
8585
STATIC_QUEUE_NOT_IN_QUEUE = -403,
86+
STATIC_QUEUE_INVALID = -404,
8687
} queueErr_t;
8788

8889
typedef enum {

0 commit comments

Comments
 (0)