]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/commitdiff
LinkedList: fix dangling references after pop
authorTimePath <andrew.hardaker1995@gmail.com>
Sat, 5 Dec 2015 10:06:08 +0000 (21:06 +1100)
committerTimePath <andrew.hardaker1995@gmail.com>
Sat, 5 Dec 2015 10:06:08 +0000 (21:06 +1100)
qcsrc/lib/linkedlist.qh

index 4946daddee31ab90b326390d07ea43964ddc3e5c..94d26e17575a55a921d32799f5dfe7a1b3650c65 100644 (file)
@@ -21,6 +21,7 @@ ENDCLASS(LinkedList)
  */
 entity LL_PUSH(LinkedList this, entity e)
 {
+       assert(this);
        LinkedListNode n = NEW(LinkedListNode);
        n.ll_data = e;
        LinkedListNode tail = n.ll_prev = this.ll_tail;
@@ -33,12 +34,14 @@ entity LL_PUSH(LinkedList this, entity e)
  */
 entity LL_POP(LinkedList this)
 {
+       assert(this);
        if (!this.ll_tail) return NULL;
        LinkedListNode n = this.ll_tail;
        entity e = n.ll_data;
        LinkedListNode prev = n.ll_prev;
-       if (prev) prev.ll_next = NULL;
+       if (prev) (this.ll_tail = prev).ll_next = NULL;
        else this.ll_head = this.ll_tail = NULL;
+       remove(n);
        return e;
 }