Bug 1398543 - Add missing condition in DoublyLinkedList::ElementNotInList. r?froydnj
--- 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;