summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRob Clark <[email protected]>2016-07-02 08:02:51 -0400
committerRob Clark <[email protected]>2016-07-06 10:17:30 -0400
commit23dd9eaa94e97450582059763fcb479e1e8fe818 (patch)
treeea64a9b14fa27c198faebb541b698d5f6dcb669b
parent09fe35b450ed15b3cfc956304e96723b4c600ad8 (diff)
list: fix list_replace() for empty lists
Before, it would happily copy list_head next/prev (ie. pointer to the *from* list_head), leaving things in a confused state and causing much mayhem. Signed-off-by: Rob Clark <[email protected]> Reviewed-by: Jason Ekstrand <[email protected]>
-rw-r--r--src/util/list.h14
1 files changed, 10 insertions, 4 deletions
diff --git a/src/util/list.h b/src/util/list.h
index f0dec5da608..e8a99ac8e00 100644
--- a/src/util/list.h
+++ b/src/util/list.h
@@ -71,12 +71,18 @@ static inline void list_addtail(struct list_head *item, struct list_head *list)
list->prev = item;
}
+static inline bool list_empty(struct list_head *list);
+
static inline void list_replace(struct list_head *from, struct list_head *to)
{
- to->prev = from->prev;
- to->next = from->next;
- from->next->prev = to;
- from->prev->next = to;
+ if (list_empty(from)) {
+ list_inithead(to);
+ } else {
+ to->prev = from->prev;
+ to->next = from->next;
+ from->next->prev = to;
+ from->prev->next = to;
+ }
}
static inline void list_del(struct list_head *item)