Просмотр исходного кода

common: tree: Avoid a nullptr dereference.

bunnei 5 лет назад
Родитель
Сommit
eee302b9b9
1 измененных файлов с 1 добавлено и 1 удалено
  1. 1 1
      src/common/tree.h

+ 1 - 1
src/common/tree.h

@@ -322,7 +322,7 @@ void RB_INSERT_COLOR(RBHead<Node>* head, Node* elm) {
 template <typename Node>
 template <typename Node>
 void RB_REMOVE_COLOR(RBHead<Node>* head, Node* parent, Node* elm) {
 void RB_REMOVE_COLOR(RBHead<Node>* head, Node* parent, Node* elm) {
     Node* tmp;
     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) {
         if (RB_LEFT(parent) == elm) {
             tmp = RB_RIGHT(parent);
             tmp = RB_RIGHT(parent);
             if (RB_IS_RED(tmp)) {
             if (RB_IS_RED(tmp)) {