Bug 1398543 - Add missing condition in DoublyLinkedList::ElementNotInList. r?froydnj draft
authorMike Hommey <mh+mozilla@glandium.org>
Sun, 10 Sep 2017 08:49:56 +0900
changeset 662001 604549e33557bfe388e988b9ebef93f19d915c89
parent 661689 ea7b55d65d76214f97aaae502d65cb26fc6f5659
child 662002 8a2cc8d9d8b5ff407cd0e9f3cc22fc5c6c2abd78
push id78921
push userbmo:mh+mozilla@glandium.org
push dateSat, 09 Sep 2017 23:50:10 +0000
reviewersfroydnj
bugs1398543
milestone57.0a1
Bug 1398543 - Add missing condition in DoublyLinkedList::ElementNotInList. r?froydnj
mfbt/DoublyLinkedList.h
--- a/mfbt/DoublyLinkedList.h
+++ b/mfbt/DoublyLinkedList.h
@@ -112,18 +112,25 @@ class DoublyLinkedList final
   /**
    * Checks that either the list is empty and both mHead and mTail are nullptr
    * or the list has entries and both mHead and mTail are non-null.
    */
   bool isStateValid() const {
     return (mHead != nullptr) == (mTail != nullptr);
   }
 
-  static bool ElementNotInList(T* aElm) {
-    return !SiblingAccess::GetNext(aElm) && !SiblingAccess::GetPrev(aElm);
+  bool ElementNotInList(T* aElm) {
+    if (!SiblingAccess::GetNext(aElm) && !SiblingAccess::GetPrev(aElm)) {
+      // Both mNext and mPrev being NULL can mean two things:
+      // - the element is not in the list.
+      // - the element is the first and only element in the list.
+      // So check for the latter.
+      return mHead != aElm;
+    }
+    return false;
   }
 
 public:
   DoublyLinkedList() : mHead(nullptr), mTail(nullptr) {}
 
   class Iterator final {
     T* mCurrent;