/* ELF strtab with GC and suffix merging support.
- Copyright (C) 2001-2020 Free Software Foundation, Inc.
+ Copyright (C) 2001-2021 Free Software Foundation, Inc.
Written by Jakub Jelinek <jakub@redhat.com>.
This file is part of BFD, the Binary File Descriptor library.
void
_bfd_elf_strtab_restore (struct elf_strtab_hash *tab, void *buf)
{
- size_t idx, curr_size = tab->size;
+ size_t idx, curr_size = tab->size, save_size;
struct strtab_save *save = (struct strtab_save *) buf;
BFD_ASSERT (tab->sec_size == 0);
- BFD_ASSERT (save->size <= curr_size);
- tab->size = save->size;
- for (idx = 1; idx < save->size; ++idx)
+ save_size = 1;
+ if (save != NULL)
+ save_size = save->size;
+ BFD_ASSERT (save_size <= curr_size);
+ tab->size = save_size;
+ for (idx = 1; idx < save_size; ++idx)
tab->array[idx]->refcount = save->refcount[idx];
for (; idx < curr_size; ++idx)
bfd_size_type *offset)
{
if (idx == 0)
- return 0;
+ return NULL;
BFD_ASSERT (idx < tab->size);
BFD_ASSERT (tab->sec_size);
+ if (tab->array[idx]->refcount == 0)
+ return NULL;
if (offset)
*offset = tab->array[idx]->u.index;
return tab->array[idx]->root.string;
}
}
-alloc_failure:
- if (array)
- free (array);
+ alloc_failure:
+ free (array);
/* Assign positions to the strings we want to keep. */
sec_size = 1;