]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
Fix uninitialised variable errors
authorAlan Modra <amodra@gmail.com>
Thu, 4 Apr 2024 00:53:32 +0000 (11:23 +1030)
committerAlan Modra <amodra@gmail.com>
Thu, 4 Apr 2024 01:03:13 +0000 (11:33 +1030)
Commit c6291d749aec introduced a number of errors, found by clang.

elf.c:456:7: error: variable 'alloc_ext_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  if (_bfd_mul_overflow (symcount, extsym_size, &amt))
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elf.c:464:7: error: variable 'alloc_extshndx_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
  if (bfd_seek (ibfd, pos, SEEK_SET) != 0
      ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
elflink.c:2837:11: error: variable 'alloc1_size' is used uninitialized whenever 'if' condition is true [-Werror,-Wsometimes-uninitialized]
      if (internal_relocs == NULL)
          ^~~~~~~~~~~~~~~~~~~~~~~
elflink.c:12595:16: error: variable 'ext_size' set but not used [-Werror,-Wunused-but-set-variable]
                      size_t ext_size = 0;

* elf.c (bfd_elf_get_elf_syms): Fix use of uninitialised variables.
* elflink.c (_bfd_elf_link_info_read_relocs): Likewise.
(bfd_elf_final_link): Fix set but not used warning.

bfd/elf.c
bfd/elflink.c

index 9b98d3b8b2ba6972d78e172737d1e3c372d22511..c305b40eca321cfe7296b7f54aaeb38b08cba140 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -456,8 +456,7 @@ bfd_elf_get_elf_syms (bfd *ibfd,
   if (_bfd_mul_overflow (symcount, extsym_size, &amt))
     {
       bfd_set_error (bfd_error_file_too_big);
-      intsym_buf = NULL;
-      goto out;
+      return NULL;
     }
   pos = symtab_hdr->sh_offset + symoffset * extsym_size;
   size_t alloc_ext_size = amt;
@@ -466,7 +465,7 @@ bfd_elf_get_elf_syms (bfd *ibfd,
                                    &alloc_ext, ibfd, false))
     {
       intsym_buf = NULL;
-      goto out;
+      goto out2;
     }
 
   size_t alloc_extshndx_size = 0;
@@ -478,7 +477,7 @@ bfd_elf_get_elf_syms (bfd *ibfd,
        {
          bfd_set_error (bfd_error_file_too_big);
          intsym_buf = NULL;
-         goto out;
+         goto out1;
        }
       alloc_extshndx_size = amt;
       pos = shndx_hdr->sh_offset + symoffset * sizeof (Elf_External_Sym_Shndx);
@@ -489,7 +488,7 @@ bfd_elf_get_elf_syms (bfd *ibfd,
                                        ibfd, false))
        {
          intsym_buf = NULL;
-         goto out;
+         goto out1;
        }
     }
 
@@ -498,12 +497,12 @@ bfd_elf_get_elf_syms (bfd *ibfd,
       if (_bfd_mul_overflow (symcount, sizeof (Elf_Internal_Sym), &amt))
        {
          bfd_set_error (bfd_error_file_too_big);
-         goto out;
+         goto out1;
        }
       alloc_intsym = (Elf_Internal_Sym *) bfd_malloc (amt);
       intsym_buf = alloc_intsym;
       if (intsym_buf == NULL)
-       goto out;
+       goto out1;
     }
 
   /* Convert the symbols to internal form.  */
@@ -521,12 +520,13 @@ bfd_elf_get_elf_syms (bfd *ibfd,
                            ibfd, (unsigned long) symoffset);
        free (alloc_intsym);
        intsym_buf = NULL;
-       goto out;
+       goto out1;
       }
 
- out:
-  _bfd_munmap_readonly_temporary (alloc_ext, alloc_ext_size);
+ out1:
   _bfd_munmap_readonly_temporary (alloc_extshndx, alloc_extshndx_size);
+ out2:
+  _bfd_munmap_readonly_temporary (alloc_ext, alloc_ext_size);
 
   return intsym_buf;
 }
index 2a05299b24dac3101e59845ef165952080e23dd1..dd7ae1705b6695596ad294a7aa87d643cac1c03b 100644 (file)
@@ -2835,7 +2835,7 @@ _bfd_elf_link_info_read_relocs (bfd *abfd,
       else
        internal_relocs = alloc2 = (Elf_Internal_Rela *) bfd_malloc (size);
       if (internal_relocs == NULL)
-       goto error_return;
+       return NULL;
     }
 
   alloc1 = external_relocs;
@@ -12592,6 +12592,7 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
 
                  if ((sec->flags & SEC_RELOC) != 0)
                    {
+#ifndef USE_MMAP
                      size_t ext_size = 0;
 
                      if (esdi->rel.hdr != NULL)
@@ -12599,7 +12600,6 @@ bfd_elf_final_link (bfd *abfd, struct bfd_link_info *info)
                      if (esdi->rela.hdr != NULL)
                        ext_size += esdi->rela.hdr->sh_size;
 
-#ifndef USE_MMAP
                      if (ext_size > max_external_reloc_size)
                        max_external_reloc_size = ext_size;
 #endif