Skip to content

Commit

Permalink
Fix LIST_INSERT_HEAD on the empty list
Browse files Browse the repository at this point in the history
Fixes #263
  • Loading branch information
yamt committed Sep 20, 2024
1 parent e2de1e3 commit 954598b
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions lib/list.c
Original file line number Diff line number Diff line change
Expand Up @@ -77,17 +77,16 @@ list_insert_head(struct list_head *h, void *elem, struct list_entry *e)
{
list_check2(h, elem, e, false);
if (h->first == NULL) {
e->next = NULL;
h->tailnextp = &e->next;
} else {
uintptr_t offset = (uintptr_t)e - (uintptr_t)elem;
struct list_entry *firstentry =
(void *)((uintptr_t)h->first + offset);
assert(firstentry->prevnextp == &h->first);
firstentry->prevnextp = &e->next;
e->next = h->first;
e->prevnextp = &h->first;
}
e->next = h->first;
e->prevnextp = &h->first;
h->first = elem;
assert(h->first != NULL);
assert(*e->prevnextp == elem);
Expand Down

0 comments on commit 954598b

Please sign in to comment.