Patchwork [Ada] Dereference correct hash table for a given node array index

login
register
mail settings
Submitter Arnaud Charlet
Date Aug. 31, 2011, 8:37 a.m.
Message ID <20110831083751.GA27238@adacore.com>
Download mbox | patch
Permalink /patch/112467/
State New
Headers show

Comments

Arnaud Charlet - Aug. 31, 2011, 8:37 a.m.
Symmetric_Difference iterates over each hash table, populating the result set
as it identifies items in one set not in the other set. The iterator works by
passing a node index value back to the caller, which it in turn uses to
dereference the node array. Both the Left and Right sets are visible in the
scope of the iterator. The problem was that when iterating over the Right set,
the index value passed back to the caller was used to dereference to the Left
set, but this is not the correct array. The fix is to use the Right index to
dereference the Right node array.

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

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

	* a-cbhase.adb (Symmetric_Difference): Dereference correct node array.
	* a-chtgbo.adb (Free): Allow 0 as index value.

Patch

Index: a-cbhase.adb
===================================================================
--- a-cbhase.adb	(revision 178355)
+++ a-cbhase.adb	(working copy)
@@ -1274,7 +1274,7 @@ 
             -------------
 
             procedure Process (R_Node : Count_Type) is
-               N : Node_Type renames Left.Nodes (R_Node);
+               N : Node_Type renames Right.Nodes (R_Node);
                X : Count_Type;
                B : Boolean;
 
Index: a-chtgbo.adb
===================================================================
--- a-chtgbo.adb	(revision 178355)
+++ a-chtgbo.adb	(working copy)
@@ -136,15 +136,19 @@ 
      (HT : in out Hash_Table_Type'Class;
       X  : Count_Type)
    is
-      pragma Assert (X > 0);
+      N : Nodes_Type renames HT.Nodes;
+
+   begin
+      if X = 0 then
+         return;
+      end if;
+
       pragma Assert (X <= HT.Capacity);
 
-      N : Nodes_Type renames HT.Nodes;
       --  pragma Assert (N (X).Prev >= 0);  -- node is active
       --  Find a way to mark a node as active vs. inactive; we could
       --  use a special value in Color_Type for this.  ???
 
-   begin
       --  The hash table actually contains two data structures: a list for
       --  the "active" nodes that contain elements that have been inserted
       --  onto the container, and another for the "inactive" nodes of the free