From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 20602 invoked by alias); 4 Apr 2005 03:21:34 -0000 Mailing-List: contact binutils-help@sources.redhat.com; run by ezmlm Precedence: bulk List-Subscribe: List-Archive: List-Post: List-Help: , Sender: binutils-owner@sources.redhat.com Received: (qmail 20556 invoked from network); 4 Apr 2005 03:21:31 -0000 Received: from unknown (HELO modra.org) (144.136.221.26) by sourceware.org with SMTP; 4 Apr 2005 03:21:31 -0000 Received: by bubble.modra.org (Postfix, from userid 500) id D5D861A0A72; Mon, 4 Apr 2005 12:51:29 +0930 (CST) Date: Mon, 04 Apr 2005 03:21:00 -0000 From: Alan Modra To: Zack Weinberg Cc: binutils@sourceware.org Subject: Re: gas/hash.c: add interface for looking up non-NUL-terminated strings Message-ID: <20050404032129.GH7121@bubble.modra.org> Mail-Followup-To: Zack Weinberg , binutils@sourceware.org References: <871x9ynrx6.fsf@codesourcery.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <871x9ynrx6.fsf@codesourcery.com> User-Agent: Mutt/1.4i X-SW-Source: 2005-04/txt/msg00055.txt.bz2 On Tue, Mar 29, 2005 at 12:00:37PM -0800, Zack Weinberg wrote: > > The appended patch adds a new interface to gas/hash.c, hash_find_n, > with exactly the same semantics as hash_find except that the length of > the key is passed in as an argument, and the key is not assumed to be > NUL-terminated. This is more convenient when parsing an assembly > instruction: one does not need to write a NUL into the line buffer so > that hash_find knows where to stop. Hmm, seems to me that writing a NUL into the line buffer isn't that onerous. I'd like to see more justification for this patch, particularly since we have too many hash table implementations already in binutils. At some stage I'd like to move bfd and gas over to use libiberty's hashtab.c, and another interface difference will make that task harder. > - if (strcmp (p->string, key) == 0) > + if (p->string[len] == '\0' && strncmp (p->string, key, len) == 0) Potential access past the end of p->string. The strncmp must come first. -- Alan Modra IBM OzLabs - Linux Technology Centre