From a5070a3b4fe5e08afa57cbe43acb205cea85edc7 Mon Sep 17 00:00:00 2001 From: TimePath Date: Sat, 5 Dec 2015 21:06:08 +1100 Subject: [PATCH] LinkedList: fix dangling references after pop --- qcsrc/lib/linkedlist.qh | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) 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; } -- 2.39.2