From: TimePath Date: Sat, 5 Dec 2015 10:06:08 +0000 (+1100) Subject: LinkedList: fix dangling references after pop X-Git-Tag: xonotic-v0.8.2~1550 X-Git-Url: https://git.rm.cloudns.org/?a=commitdiff_plain;h=a5070a3b4fe5e08afa57cbe43acb205cea85edc7;p=xonotic%2Fxonotic-data.pk3dir.git LinkedList: fix dangling references after pop --- diff --git a/qcsrc/lib/linkedlist.qh b/qcsrc/lib/linkedlist.qh index 4946dadde..94d26e175 100644 --- a/qcsrc/lib/linkedlist.qh +++ b/qcsrc/lib/linkedlist.qh @@ -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; }