This is the mail archive of the binutils@sourceware.org mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: PATCH: robustify bfd/linker.c:archive_hash_newfunc


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]