Skip to content

Commit

Permalink
Shared/LinkedList: Fix delink logic to handle first and last elements…
Browse files Browse the repository at this point in the history
… in linked list
  • Loading branch information
walkline committed Jan 10, 2025
1 parent d8240fb commit 6f35458
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/server/shared/Dynamic/LinkedList.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class LinkedListElement

bool hasNext() const { return (iNext && iNext->iNext != nullptr); }
bool hasPrev() const { return (iPrev && iPrev->iPrev != nullptr); }
bool isInList() const { return (iNext != nullptr && iPrev != nullptr); }
bool isInList() const { return (iNext != nullptr || iPrev != nullptr); }

LinkedListElement * next() { return hasNext() ? iNext : nullptr; }
LinkedListElement const* next() const { return hasNext() ? iNext : nullptr; }
Expand All @@ -54,8 +54,11 @@ class LinkedListElement
if (!isInList())
return;

iNext->iPrev = iPrev;
iPrev->iNext = iNext;
if (iNext)
iNext->iPrev = iPrev;
if (iPrev)
iPrev->iNext = iNext;

iNext = nullptr;
iPrev = nullptr;
}
Expand Down

0 comments on commit 6f35458

Please sign in to comment.