Skip to content

Commit 1a483c7

Browse files
committed
cllist_append append improvement
cllist_append() depends on cur always pointing to the tail; appending after list traversal may corrupt the list. A dedicated tail pointer would avoid misuse.
1 parent 31a3ad7 commit 1a483c7

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

auparse/normalize-llist.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ void cllist_create(cllist *l, void (*cleanup)(void *))
2828
{
2929
l->head = NULL;
3030
l->cur = NULL;
31+
l->tail = NULL;
3132
l->cleanup = cleanup;
3233
l->cnt = 0;
3334
}
@@ -50,6 +51,7 @@ void cllist_clear(cllist *l)
5051
}
5152
l->head = NULL;
5253
l->cur = NULL;
54+
l->tail = NULL;
5355
l->cnt = 0;
5456
}
5557

@@ -78,9 +80,10 @@ int cllist_append(cllist *l, uint32_t num, void *data)
7880
if (l->head == NULL)
7981
l->head = newnode;
8082
else // Otherwise add pointer to newnode
81-
l->cur->next = newnode;
83+
l->tail->next = newnode;
8284

83-
// make newnode current
85+
// update tail and make newnode current
86+
l->tail = newnode;
8487
l->cur = newnode;
8588
l->cnt++;
8689
return 0;

auparse/normalize-llist.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ typedef struct _data_node {
4141
typedef struct {
4242
data_node *head; // List head
4343
data_node *cur; // Pointer to current node
44+
data_node *tail; // Pointer to last node
4445
void (*cleanup)(void *); // Function to call when releasing memory
4546
unsigned int cnt; // How many items in this list
4647
} cllist;

0 commit comments

Comments
 (0)