From patchwork Wed Aug 31 08:37:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arnaud Charlet X-Patchwork-Id: 112467 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 635E7B6F7F for ; Wed, 31 Aug 2011 18:38:29 +1000 (EST) Received: (qmail 2157 invoked by alias); 31 Aug 2011 08:38:21 -0000 Received: (qmail 1928 invoked by uid 22791); 31 Aug 2011 08:38:19 -0000 X-SWARE-Spam-Status: No, hits=-1.8 required=5.0 tests=AWL,BAYES_00 X-Spam-Check-By: sourceware.org Received: from rock.gnat.com (HELO rock.gnat.com) (205.232.38.15) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Wed, 31 Aug 2011 08:37:52 +0000 Received: from localhost (localhost.localdomain [127.0.0.1]) by filtered-rock.gnat.com (Postfix) with ESMTP id 22F232BB234; Wed, 31 Aug 2011 04:37:52 -0400 (EDT) Received: from rock.gnat.com ([127.0.0.1]) by localhost (rock.gnat.com [127.0.0.1]) (amavisd-new, port 10024) with LMTP id phh96TqMy1h4; Wed, 31 Aug 2011 04:37:52 -0400 (EDT) Received: from kwai.gnat.com (kwai.gnat.com [205.232.38.4]) by rock.gnat.com (Postfix) with ESMTP id 104F12BAF27; Wed, 31 Aug 2011 04:37:52 -0400 (EDT) Received: by kwai.gnat.com (Postfix, from userid 4192) id 00C3A3FEE8; Wed, 31 Aug 2011 04:37:51 -0400 (EDT) Date: Wed, 31 Aug 2011 04:37:51 -0400 From: Arnaud Charlet To: gcc-patches@gcc.gnu.org Cc: Matthew Heaney Subject: [Ada] Dereference correct hash table for a given node array index Message-ID: <20110831083751.GA27238@adacore.com> MIME-Version: 1.0 Content-Disposition: inline User-Agent: Mutt/1.5.20 (2009-06-14) Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org 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 * a-cbhase.adb (Symmetric_Difference): Dereference correct node array. * a-chtgbo.adb (Free): Allow 0 as index value. 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