rbtree: Fix a crash in insertion fixup

This got broken in commit a33ff4c6ab.

Testcase included.
This commit is contained in:
Benjamin Otte 2019-01-20 06:07:52 +01:00
parent 5e00cdbd74
commit af56f06b7b
2 changed files with 18 additions and 3 deletions

View File

@ -382,9 +382,9 @@ gtk_rb_tree_insert_fixup (GtkRbTree *tree,
{
/* make node a left child */
node = p;
gtk_rb_node_rotate_left (tree, node);
p = parent (node);
pp = parent (p);
gtk_rb_node_rotate_left (tree, node);
}
/* recolor and rotate */
set_black (p);
@ -411,9 +411,9 @@ gtk_rb_tree_insert_fixup (GtkRbTree *tree,
if (node == p->left)
{
node = p;
gtk_rb_node_rotate_right (tree, node);
p = parent (node);
pp = parent (p);
gtk_rb_node_rotate_right (tree, node);
}
set_black (p);
set_red (pp);

View File

@ -273,6 +273,20 @@ test_crash (void)
gtk_rb_tree_unref (tree);
}
static void
test_crash2 (void)
{
GtkRbTree *tree;
tree = gtk_rb_tree_new (Node, Aug, augment, NULL, NULL);
add (tree, 0);
add (tree, 0);
add (tree, 1);
gtk_rb_tree_unref (tree);
}
int
main (int argc, char *argv[])
{
@ -280,7 +294,8 @@ main (int argc, char *argv[])
setlocale (LC_ALL, "C");
g_test_bug_base ("http://bugzilla.gnome.org/show_bug.cgi?id=%s");
g_test_add_func ("/csrbtree/crash", test_crash);
g_test_add_func ("/rbtree/crash", test_crash);
g_test_add_func ("/rbtree/crash2", test_crash2);
return g_test_run ();
}