This is the mail archive of the
binutils@sourceware.org
mailing list for the binutils project.
Re: PATCH: robustify bfd/linker.c:archive_hash_newfunc
- From: Ian Lance Taylor <iant at google dot com>
- To: Ben Elliston <bje at au1 dot ibm dot com>
- Cc: binutils at sourceware dot org
- Date: 24 Oct 2006 07:23:27 -0700
- Subject: Re: PATCH: robustify bfd/linker.c:archive_hash_newfunc
- References: <20061024070056.GD17102@ozlabs.au.ibm.com>
Ben Elliston <bje@au1.ibm.com> writes:
> I think the last time I raised this, I was told that `root' will
> always be the first field of a struct archive_hash_entry. That
> bothers me .. is this more explicit handling of return values just as
> acceptable?
>
> Ben
>
>
> 2006-10-24 Ben Elliston <bje@au.ibm.com>
>
> * linker.c (archive_hash_newfunc): Return NULL if ret is NULL,
> rather than assuming that `root' is the first field of a struct
> archive_hash_entry.
The root field must always be the first field of all the hash_entry
structs. If that ever fails for any hash_entry struct, the hash table
code will fail. So the assumption in this code is completely valid.
If you want to rework this function, I think you should rework it to
look like all the other newfunc functions:
if (entry == NULL)
{
entry = bfd_hash_allocate (table, sizeof (struct archive_hash_entry));
if (entry == NULL)
return entry;
}
/* Call the allocation method of the superclass. */
entry = bfd_hash_newfunc (entry, table, string);
if (entry)
{
struct archive_hash_entry *ret;
/* Initialize the local fields. */
ret = (struct archive_hash_entry *) entry;
ret->defs = NULL;
}
return entry;
Ian