summaryrefslogtreecommitdiff
path: root/ace/RB_Tree.cpp
diff options
context:
space:
mode:
authorcdgill <cdgill@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-10 17:20:45 +0000
committercdgill <cdgill@ae88bc3d-4319-0410-8dbf-d08b4c9d3795>1999-05-10 17:20:45 +0000
commit49d36abbea370bc540d02b232ee5198f25a1386c (patch)
treeafe216a9d36f8e37cb61ca42b3f0e6347fc5a7e8 /ace/RB_Tree.cpp
parente6700ff8bafec2bb45743264b8b29376fc98fd00 (diff)
downloadATCD-49d36abbea370bc540d02b232ee5198f25a1386c.tar.gz
fixed dangling pointer bug
Diffstat (limited to 'ace/RB_Tree.cpp')
-rw-r--r--ace/RB_Tree.cpp38
1 files changed, 29 insertions, 9 deletions
diff --git a/ace/RB_Tree.cpp b/ace/RB_Tree.cpp
index 2abb9cfcbcb..51ce070f278 100644
--- a/ace/RB_Tree.cpp
+++ b/ace/RB_Tree.cpp
@@ -276,14 +276,23 @@ ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_delete_fixup (ACE_RB_Tre
(!w->right () ||
w->right ()->color () == ACE_RB_Tree_Node_Base::BLACK))
{
- w->left ()->color (ACE_RB_Tree_Node_Base::BLACK);
+ if (w->left ())
+ {
+ w->left ()->color (ACE_RB_Tree_Node_Base::BLACK);
+ }
w->color (ACE_RB_Tree_Node_Base::RED);
RB_rotate_right (w);
w = x->parent ()->right ();
}
- w->color (x->parent ()->color ());
+ if (w)
+ {
+ w->color (x->parent ()->color ());
+ if (w->right ())
+ {
+ w->right ()->color (ACE_RB_Tree_Node_Base::BLACK);
+ }
+ }
x->parent ()->color (ACE_RB_Tree_Node_Base::BLACK);
- w->right ()->color (ACE_RB_Tree_Node_Base::BLACK);
RB_rotate_left (x->parent ());
x = root_;
}
@@ -299,7 +308,8 @@ ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_delete_fixup (ACE_RB_Tre
w = x->parent ()->left ();
}
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
- if ((!w->left () ||
+ if (w &&
+ (!w->left () ||
w->left ()->color () == ACE_RB_Tree_Node_Base::BLACK) &&
(!w->right () ||
w->right ()->color () == ACE_RB_Tree_Node_Base::BLACK))
@@ -310,17 +320,27 @@ ACE_RB_Tree<EXT_ID, INT_ID, COMPARE_KEYS, ACE_LOCK>::RB_delete_fixup (ACE_RB_Tre
else
{
// CLR pp. 263 says that nil nodes are implicitly colored BLACK
- if (!w->left () ||
- w->left ()->color () == ACE_RB_Tree_Node_Base::BLACK)
+ if (w &&
+ (!w->left () ||
+ w->left ()->color () == ACE_RB_Tree_Node_Base::BLACK))
{
- w->right ()->color (ACE_RB_Tree_Node_Base::BLACK);
w->color (ACE_RB_Tree_Node_Base::RED);
+ if (w->right ())
+ {
+ w->right ()->color (ACE_RB_Tree_Node_Base::BLACK);
+ }
RB_rotate_left (w);
w = x->parent ()->left ();
}
- w->color (x->parent ()->color ());
+ if (w)
+ {
+ w->color (x->parent ()->color ());
+ if (w->left ())
+ {
+ w->left ()->color (ACE_RB_Tree_Node_Base::BLACK);
+ }
+ }
x->parent ()->color (ACE_RB_Tree_Node_Base::BLACK);
- w->left ()->color (ACE_RB_Tree_Node_Base::BLACK);
RB_rotate_right (x->parent ());
x = root_;
}