This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: gas/hash.c: add interface for looking up non-NUL-terminated strings
- From: Alan Modra <amodra at bigpond dot net dot au>
- To: Zack Weinberg <zack at codesourcery dot com>
- Cc: binutils at sourceware dot org
- Date: Mon, 4 Apr 2005 12:51:29 +0930
- Subject: Re: gas/hash.c: add interface for looking up non-NUL-terminated strings
- References: <871x9ynrx6.fsf@codesourcery.com>
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