[libgee] Fix a bug in TreeMap implementation



commit 5236badaa8b972bd9f74ab8e1a561d04b8bbcd88
Author: Julien Peeters <contact julienpeeters fr>
Date:   Fri Sep 11 21:01:27 2009 +0200

    Fix a bug in TreeMap implementation
    
    Fixes part of bug 594868.
    
    The access to child nodes two level deeper does not check that the
    child at the intermediate level is not null.

 gee/treemap.vala |    6 +++---
 1 files changed, 3 insertions(+), 3 deletions(-)
---
diff --git a/gee/treemap.vala b/gee/treemap.vala
index 69d374a..53c40cc 100644
--- a/gee/treemap.vala
+++ b/gee/treemap.vala
@@ -180,7 +180,7 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
 
 	private void move_red_left (ref Node<K, V> root) {
 		root.flip ();
-		if (is_red (root.right.left)) {
+		if (root.right != null && is_red (root.right.left)) {
 			rotate_right (ref root.right);
 			rotate_left (ref root);
 			root.flip ();
@@ -189,7 +189,7 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
 
 	private void move_red_right (ref Node<K, V> root) {
 		root.flip ();
-		if (is_red (root.left.left)) {
+		if (root.left != null && is_red (root.left.left)) {
 			rotate_right (ref root.right);
 			root.flip ();
 		}
@@ -239,7 +239,7 @@ public class Gee.TreeMap<K,V> : Gee.AbstractMap<K,V> {
 				_size--;
 				return true;
 			}
-			if (is_black (r) && is_black (r.left)) {
+			if (r == null || (is_black (r) && is_black (r.left))) {
 				move_red_right (ref node);
 			}
 			if (key_compare_func (key, node.key) == 0) {



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]