[binutils-gdb] Revert "Replace assertions with error return values, thus ensuring an illegal memory access does not

Alan Modra amodra@sourceware.org
Fri May 30 23:43:23 GMT 2025


https://sourceware.org/git/gitweb.cgi?p=binutils-gdb.git;h=47d7ab705754543cd8b2671aae134163f22852c8

commit 47d7ab705754543cd8b2671aae134163f22852c8
Author: Alan Modra <amodra@gmail.com>
Date:   Sat May 31 08:15:45 2025 +0930

    Revert "Replace assertions with error return values, thus ensuring an illegal memory access does not occur."
    
    This reverts commit 429fb15134cfbdafe2b203086ee05d827726b63b.

Diff:
---
 bfd/elf-strtab.c | 7 ++++---
 bfd/elf.c        | 9 +++------
 2 files changed, 7 insertions(+), 9 deletions(-)

diff --git a/bfd/elf-strtab.c b/bfd/elf-strtab.c
index 52a0895fb43..9b0b0b8ec60 100644
--- a/bfd/elf-strtab.c
+++ b/bfd/elf-strtab.c
@@ -285,11 +285,12 @@ _bfd_elf_strtab_offset (struct elf_strtab_hash *tab, size_t idx)
 {
   struct elf_strtab_hash_entry *entry;
 
-  if (idx == 0 || idx >= tab->size || tab->sec_size == 0)
+  if (idx == 0)
     return 0;
+  BFD_ASSERT (idx < tab->size);
+  BFD_ASSERT (tab->sec_size);
   entry = tab->array[idx];
-  if (entry == NULL || entry->refcount == 0)
-    return 0;
+  BFD_ASSERT (entry->refcount > 0);
   entry->refcount--;
   return tab->array[idx]->u.index;
 }
diff --git a/bfd/elf.c b/bfd/elf.c
index 61910f8909a..3073f860621 100644
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -7161,12 +7161,9 @@ _bfd_elf_write_object_contents (bfd *abfd)
     {
       /* Don't set the sh_name field without section header.  */
       if ((abfd->flags & BFD_NO_SECTION_HEADER) == 0)
-	{
-	  i_shdrp[count]->sh_name
-	    = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
-				      i_shdrp[count]->sh_name);
-	  /* FIXME: If we could not set the section name, should we tell the user ?  */
-	}
+	i_shdrp[count]->sh_name
+	  = _bfd_elf_strtab_offset (elf_shstrtab (abfd),
+				    i_shdrp[count]->sh_name);
       if (bed->elf_backend_section_processing)
 	if (!(*bed->elf_backend_section_processing) (abfd, i_shdrp[count]))
 	  return false;


More information about the Binutils-cvs mailing list