Patchwork [Ada] Initialize pointer components of red-black tree node

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 31, 2011, 9:07 a.m.
Message ID <20110831090746.GA6515@adacore.com>
Download mbox | patch
Permalink /patch/112477/
State New
Headers show

Comments

Arnaud Charlet - Aug. 31, 2011, 9:07 a.m.
When a node is allocated from the free store, its pointer components (the links
to other nodes in the tree) must also be initialized (to 0, the equivalent of
null). This simplifies the post-allocation handling of nodes inserted into
terminal positions.

Tested on x86_64-pc-linux-gnu, committed on trunk

2011-08-31  Matthew Heaney  <heaney@adacore.com>

	* a-rbtgbo.adb (Generic_Allocate): Initialize pointer components of
	node to null value.

Patch

Index: a-rbtgbo.adb
===================================================================
--- a-rbtgbo.adb	(revision 178358)
+++ a-rbtgbo.adb	(working copy)
@@ -6,7 +6,7 @@ 
 --                                                                          --
 --                                 B o d y                                  --
 --                                                                          --
---          Copyright (C) 2004-2010, Free Software Foundation, Inc.         --
+--          Copyright (C) 2004-2011, Free Software Foundation, Inc.         --
 --                                                                          --
 -- GNAT is free software;  you can  redistribute it  and/or modify it under --
 -- terms of the  GNU General Public License as published  by the Free Soft- --
@@ -586,6 +586,10 @@ 
          Set_Element (N (Node));
          Tree.Free := Tree.Free - 1;
       end if;
+
+      Set_Parent (N (Node), Parent => 0);
+      Set_Left (N (Node), Left => 0);
+      Set_Right (N (Node), Right => 0);
    end Generic_Allocate;
 
    -------------------