X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=bfd%2Felf-strtab.c;h=35b821953df67cc503ccb349c054be1afecf6095;hb=91ed9b71fa737ff4a4519f84c5e0ae0d544514f1;hp=cc1dcb3f50a22c47095b981e6d84b943fc627dfc;hpb=22ccb8495447fa2ea31b1f1dea7e94eecf97475d;p=deliverable%2Fbinutils-gdb.git diff --git a/bfd/elf-strtab.c b/bfd/elf-strtab.c index cc1dcb3f50..35b821953d 100644 --- a/bfd/elf-strtab.c +++ b/bfd/elf-strtab.c @@ -1,5 +1,5 @@ /* ELF strtab with GC and suffix merging support. - Copyright (C) 2001-2019 Free Software Foundation, Inc. + Copyright (C) 2001-2020 Free Software Foundation, Inc. Written by Jakub Jelinek . This file is part of BFD, the Binary File Descriptor library. @@ -95,7 +95,7 @@ struct elf_strtab_hash * _bfd_elf_strtab_init (void) { struct elf_strtab_hash *table; - bfd_size_type amt = sizeof (struct elf_strtab_hash); + size_t amt = sizeof (struct elf_strtab_hash); table = (struct elf_strtab_hash *) bfd_malloc (amt); if (table == NULL) @@ -245,13 +245,16 @@ _bfd_elf_strtab_save (struct elf_strtab_hash *tab) 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) @@ -334,7 +337,9 @@ _bfd_elf_strtab_emit (register bfd *abfd, struct elf_strtab_hash *tab) return TRUE; } -/* Compare two elf_strtab_hash_entry structures. Called via qsort. */ +/* Compare two elf_strtab_hash_entry structures. Called via qsort. + Won't ever return zero as all entries differ, so there is no issue + with qsort stability here. */ static int strrevcmp (const void *a, const void *b) @@ -437,7 +442,7 @@ _bfd_elf_strtab_finalize (struct elf_strtab_hash *tab) } } -alloc_failure: + alloc_failure: if (array) free (array);