aboutsummaryrefslogtreecommitdiff
path: root/bfd/elflink.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-02-19 13:14:45 +1030
committerAlan Modra <amodra@gmail.com>2020-02-19 13:14:45 +1030
commit446f7ed5abfd2d0bed8c4442d0634b1a8bc116f4 (patch)
tree8e1fac2505e01df41dc5991026fb3733f03442bb /bfd/elflink.c
parentb03202e32c8235997b3485b0b4655926ad97a1cc (diff)
downloadgdb-446f7ed5abfd2d0bed8c4442d0634b1a8bc116f4.zip
gdb-446f7ed5abfd2d0bed8c4442d0634b1a8bc116f4.tar.gz
gdb-446f7ed5abfd2d0bed8c4442d0634b1a8bc116f4.tar.bz2
alloc2 used unnecessarily
The bfd_alloc2 series of functions were invented to handle cases where nmemb * size can overflow. This patch changes some places where the calculation can't overflow. * elf.c (bfd_section_from_shdr): Use bfd_zalloc rather than bfd_zalloc2. (assign_section_numbers): Likewise. (elf_map_symbols): Likewise, and bfd_alloc rather than bfd_alloc2. (_bfd_elf_map_sections_to_segments): Use bfd_malloc rather than bfd_malloc2, size_t amt, and unsigned tls_count. (rewrite_elf_program_header): Use bfd_malloc and size_t amt. * elflink.c (elf_create_symbuf): Use bfd_malloc. (elf_output_implib): Use bfd_alloc.
Diffstat (limited to 'bfd/elflink.c')
-rw-r--r--bfd/elflink.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/bfd/elflink.c b/bfd/elflink.c
index f7b867c..1656978e 100644
--- a/bfd/elflink.c
+++ b/bfd/elflink.c
@@ -7931,9 +7931,10 @@ elf_create_symbuf (size_t symcount, Elf_Internal_Sym *isymbuf)
Elf_Internal_Sym **ind, **indbufend, **indbuf;
struct elf_symbuf_symbol *ssym;
struct elf_symbuf_head *ssymbuf, *ssymhead;
- size_t i, shndx_count, total_size;
+ size_t i, shndx_count, total_size, amt;
- indbuf = (Elf_Internal_Sym **) bfd_malloc2 (symcount, sizeof (*indbuf));
+ amt = symcount * sizeof (*indbuf);
+ indbuf = (Elf_Internal_Sym **) bfd_malloc (amt);
if (indbuf == NULL)
return NULL;
@@ -11657,6 +11658,7 @@ elf_output_implib (bfd *abfd, struct bfd_link_info *info)
long symcount;
long src_count;
elf_symbol_type *osymbuf;
+ size_t amt;
implib_bfd = info->out_implib_bfd;
bed = get_elf_backend_data (abfd);
@@ -11714,8 +11716,8 @@ elf_output_implib (bfd *abfd, struct bfd_link_info *info)
/* Make symbols absolute. */
- osymbuf = (elf_symbol_type *) bfd_alloc2 (implib_bfd, symcount,
- sizeof (*osymbuf));
+ amt = symcount * sizeof (*osymbuf);
+ osymbuf = (elf_symbol_type *) bfd_alloc (implib_bfd, amt);
if (osymbuf == NULL)
goto free_sym_buf;