Code: Select all
Index: include/irrMap.h
===================================================================
--- include/irrMap.h (revision 1444)
+++ include/irrMap.h (working copy)
@@ -830,7 +830,10 @@
{
Root = newRoot;
if (Root != 0)
+ {
Root->setParent(0);
+ Root->setBlack(); // The root must always be black
+ }
}
//! Insert a node into the tree without using any fancy balancing logic.
Test case that demonstrates the crash (when unpatched) and better behaviour after patching:
Code: Select all
#include <irrlicht.h>
#pragma comment(lib, "Irrlicht.lib")
int main()
{
irr::core::map<int, int> myMap;
(void)myMap.insert(2, 0);
(void)myMap.insert(3, 0);
myMap.remove(2); // removes the root
(void)myMap.insert(0, 0); // crashes here
// The following exercises the code after the patch
myMap.remove(3); // remove the new root
(void)myMap.insert(2, 0);
(void)myMap.insert(4, 0);
(void)myMap.insert(1, 0);
(void)myMap.insert(3, 0);
myMap.remove(2); // removes the root again
(void)myMap.insert(0, 0);
return 0;
}