summaryrefslogtreecommitdiff
path: root/src/adlist.c
diff options
context:
space:
mode:
authorantirez <antirez@gmail.com>2017-05-03 14:15:25 +0200
committerantirez <antirez@gmail.com>2017-05-03 14:15:25 +0200
commit79226cb9fad57c958417263e52f7bb7f9b13597c (patch)
tree22fe40ca01e23551e0f698df58ef221f2e68719c /src/adlist.c
parent6798736909b7301242b023c288d2a956ec7154f4 (diff)
downloadredis-79226cb9fad57c958417263e52f7bb7f9b13597c.tar.gz
adlist: fix listJoin() to handle empty lists.
Diffstat (limited to 'src/adlist.c')
-rw-r--r--src/adlist.c10
1 files changed, 8 insertions, 2 deletions
diff --git a/src/adlist.c b/src/adlist.c
index 96575c72e..0f2e4a559 100644
--- a/src/adlist.c
+++ b/src/adlist.c
@@ -345,8 +345,14 @@ void listRotate(list *list) {
/* Add all the elements of the list 'o' at the end of the
* list 'l'. The list 'other' remains empty but otherwise valid. */
void listJoin(list *l, list *o) {
- l->tail->next = o->head;
- o->head->prev = l->tail;
+ if (o->head)
+ o->head->prev = l->tail;
+
+ if (l->tail)
+ l->tail->next = o->head;
+ else
+ l->head = o->head;
+
l->tail = o->tail;
/* Setup other as an empty list. */