diff options
| author | 2021-05-16 00:54:15 -0700 | |
|---|---|---|
| committer | 2021-05-20 21:41:51 -0700 | |
| commit | 342170fcd364b584c381f53b405c89ae3ca5e3e8 (patch) | |
| tree | 8ea42686a67477539d627adc4332245e2682715a | |
| parent | hle: kernel: Implement CloneCurrentObject and improve session management. (diff) | |
| download | yuzu-342170fcd364b584c381f53b405c89ae3ca5e3e8.tar.gz yuzu-342170fcd364b584c381f53b405c89ae3ca5e3e8.tar.xz yuzu-342170fcd364b584c381f53b405c89ae3ca5e3e8.zip | |
common: tree: Avoid a crash on nullptr dereference.
| -rw-r--r-- | src/common/tree.h | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/src/common/tree.h b/src/common/tree.h index 9d2d0df4e..18faa4a48 100644 --- a/src/common/tree.h +++ b/src/common/tree.h | |||
| @@ -43,6 +43,8 @@ | |||
| 43 | * The maximum height of a red-black tree is 2lg (n+1). | 43 | * The maximum height of a red-black tree is 2lg (n+1). |
| 44 | */ | 44 | */ |
| 45 | 45 | ||
| 46 | #include "common/assert.h" | ||
| 47 | |||
| 46 | namespace Common { | 48 | namespace Common { |
| 47 | template <typename T> | 49 | template <typename T> |
| 48 | class RBHead { | 50 | class RBHead { |
| @@ -325,6 +327,10 @@ void RB_REMOVE_COLOR(RBHead<Node>* head, Node* parent, Node* elm) { | |||
| 325 | while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head->Root() && parent != nullptr) { | 327 | while ((elm == nullptr || RB_IS_BLACK(elm)) && elm != head->Root() && parent != nullptr) { |
| 326 | if (RB_LEFT(parent) == elm) { | 328 | if (RB_LEFT(parent) == elm) { |
| 327 | tmp = RB_RIGHT(parent); | 329 | tmp = RB_RIGHT(parent); |
| 330 | if (!tmp) { | ||
| 331 | ASSERT_MSG(false, "tmp is invalid!"); | ||
| 332 | break; | ||
| 333 | } | ||
| 328 | if (RB_IS_RED(tmp)) { | 334 | if (RB_IS_RED(tmp)) { |
| 329 | RB_SET_BLACKRED(tmp, parent); | 335 | RB_SET_BLACKRED(tmp, parent); |
| 330 | RB_ROTATE_LEFT(head, parent, tmp); | 336 | RB_ROTATE_LEFT(head, parent, tmp); |
| @@ -366,6 +372,11 @@ void RB_REMOVE_COLOR(RBHead<Node>* head, Node* parent, Node* elm) { | |||
| 366 | tmp = RB_LEFT(parent); | 372 | tmp = RB_LEFT(parent); |
| 367 | } | 373 | } |
| 368 | 374 | ||
| 375 | if (!tmp) { | ||
| 376 | ASSERT_MSG(false, "tmp is invalid!"); | ||
| 377 | break; | ||
| 378 | } | ||
| 379 | |||
| 369 | if ((RB_LEFT(tmp) == nullptr || RB_IS_BLACK(RB_LEFT(tmp))) && | 380 | if ((RB_LEFT(tmp) == nullptr || RB_IS_BLACK(RB_LEFT(tmp))) && |
| 370 | (RB_RIGHT(tmp) == nullptr || RB_IS_BLACK(RB_RIGHT(tmp)))) { | 381 | (RB_RIGHT(tmp) == nullptr || RB_IS_BLACK(RB_RIGHT(tmp)))) { |
| 371 | RB_SET_COLOR(tmp, EntryColor::Red); | 382 | RB_SET_COLOR(tmp, EntryColor::Red); |