mirror of
https://github.com/espressif/binutils-gdb.git
synced 2025-09-09 23:32:21 +08:00
* libbfd-in.h (bfd_malloc2, bfd_realloc2, bfd_zmalloc2, bfd_alloc2,
bfd_zalloc2): New prototypes. * bfd-in.h (HALF_BFD_SIZE_TYPE): Define. * libbfd.c (bfd_malloc2, bfd_realloc2, bfd_zmalloc2): New functions. * opncls.c (bfd_alloc2, bfd_zalloc2): New functions. * elf.c (bfd_elf_get_elf_syms, setup_group, assign_section_numbers, elf_map_symbols, map_sections_to_segments, assign_file_positions_for_segments, copy_private_bfd_data, swap_out_syms, _bfd_elf_slurp_version_tables): Use bfd_*alloc2 where appropriate. * bfd-in2.h: Rebuilt. * libbfd.h: Rebuilt. * elf.c (_bfd_elf_print_private_bfd_data): Don't crash on bogus verdef or verneed section. (_bfd_elf_slurp_version_tables): Handle corrupt verdef and/or verneed sections gracefully. * elfxx-sparc.c (_bfd_sparc_elf_info_to_howto_ptr): Don't crash on bogus relocation values. * elf64-ppc.c (ppc64_elf_info_to_howto): Likewise. * elf64-s390.c (elf_s390_info_to_howto): Likewise. * elf32-s390.c (elf_s390_info_to_howto): Likewise. * elf64-x86-64.c (elf64_x86_64_info_to_howto): Likewise. * elfxx-ia64.c (lookup_howto): Likewise.
This commit is contained in:
72
bfd/opncls.c
72
bfd/opncls.c
@ -856,6 +856,45 @@ bfd_alloc (bfd *abfd, bfd_size_type size)
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
INTERNAL_FUNCTION
|
||||
bfd_alloc2
|
||||
|
||||
SYNOPSIS
|
||||
void *bfd_alloc2 (bfd *abfd, bfd_size_type nmemb, bfd_size_type size);
|
||||
|
||||
DESCRIPTION
|
||||
Allocate a block of @var{nmemb} elements of @var{size} bytes each
|
||||
of memory attached to <<abfd>> and return a pointer to it.
|
||||
*/
|
||||
|
||||
void *
|
||||
bfd_alloc2 (bfd *abfd, bfd_size_type nmemb, bfd_size_type size)
|
||||
{
|
||||
void *ret;
|
||||
|
||||
if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
|
||||
&& size != 0
|
||||
&& nmemb > ~(bfd_size_type) 0 / size)
|
||||
{
|
||||
bfd_set_error (bfd_error_no_memory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size *= nmemb;
|
||||
|
||||
if (size != (unsigned long) size)
|
||||
{
|
||||
bfd_set_error (bfd_error_no_memory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
ret = objalloc_alloc (abfd->memory, (unsigned long) size);
|
||||
if (ret == NULL)
|
||||
bfd_set_error (bfd_error_no_memory);
|
||||
return ret;
|
||||
}
|
||||
|
||||
/*
|
||||
INTERNAL_FUNCTION
|
||||
bfd_zalloc
|
||||
@ -879,6 +918,39 @@ bfd_zalloc (bfd *abfd, bfd_size_type size)
|
||||
return res;
|
||||
}
|
||||
|
||||
/*
|
||||
INTERNAL_FUNCTION
|
||||
bfd_zalloc2
|
||||
|
||||
SYNOPSIS
|
||||
void *bfd_zalloc2 (bfd *abfd, bfd_size_type nmemb, bfd_size_type size);
|
||||
|
||||
DESCRIPTION
|
||||
Allocate a block of @var{nmemb} elements of @var{size} bytes each
|
||||
of zeroed memory attached to <<abfd>> and return a pointer to it.
|
||||
*/
|
||||
|
||||
void *
|
||||
bfd_zalloc2 (bfd *abfd, bfd_size_type nmemb, bfd_size_type size)
|
||||
{
|
||||
void *res;
|
||||
|
||||
if ((nmemb | size) >= HALF_BFD_SIZE_TYPE
|
||||
&& size != 0
|
||||
&& nmemb > ~(bfd_size_type) 0 / size)
|
||||
{
|
||||
bfd_set_error (bfd_error_no_memory);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
size *= nmemb;
|
||||
|
||||
res = bfd_alloc (abfd, size);
|
||||
if (res)
|
||||
memset (res, 0, (size_t) size);
|
||||
return res;
|
||||
}
|
||||
|
||||
/* Free a block allocated for a BFD.
|
||||
Note: Also frees all more recently allocated blocks! */
|
||||
|
||||
|
Reference in New Issue
Block a user