PATCH: robustify bfd/linker.c:archive_hash_newfunc

Ian Lance Taylor
Wed Oct 25 06:47:00 GMT 2006

Ben Elliston <> 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  <>
>         * 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;


More information about the Binutils mailing list