Skip to content

VERY experimental Nintendo Switch 2 emulator

C++

common: tree: Avoid a nullptr dereference.

bunnei9d01b31e3f31
diff --git a/src/common/tree.h b/src/common/tree.h
index 3da49e422f..9d2d0df4e7 100644
--- a/src/common/tree.h
+++ b/src/common/tree.h
@@ -322,7 +322,7 @@ void RB_INSERT_COLOR(RBHead<Node>* head, Node* elm) {
template <typename Node>
void RB_REMOVE_COLOR(RBHead<Node>* head, Node* parent, Node* elm) {
Node* tmp;
- while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head->Root()) {
+ while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head->Root() && parent != nullptr) {
if (RB_LEFT(parent) == elm) {
tmp = RB_RIGHT(parent);
if (RB_IS_RED(tmp)) {