aboutsummaryrefslogtreecommitdiff
path: root/binutils/objcopy.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2017-07-01 21:58:10 +0930
committerAlan Modra <amodra@gmail.com>2017-07-02 08:33:12 +0930
commitbae7501e87ab614115d9d3213b4dd18d96e604db (patch)
treee0b4a01a423eb5d078903002b6a0223e575069cd /binutils/objcopy.c
parent25c5412713badef8cf779186174200ecd880b329 (diff)
downloadgdb-bae7501e87ab614115d9d3213b4dd18d96e604db.zip
gdb-bae7501e87ab614115d9d3213b4dd18d96e604db.tar.gz
gdb-bae7501e87ab614115d9d3213b4dd18d96e604db.tar.bz2
Use bfd_malloc_and_get_section
It's nicer than xmalloc followed by bfd_get_section_contents, since xmalloc exits on failure and needs a check that its size_t arg doesn't lose high bits when converted from bfd_size_type. PR binutils/21665 * objdump.c (strtab): Make var a bfd_byte*. (disassemble_section): Don't limit malloc size. Instead, use bfd_malloc_and_get_section. (read_section_stabs): Use bfd_malloc_and_get_section. Return bfd_byte*. (find_stabs_section): Remove now unnecessary cast. * objcopy.c (copy_object): Use bfd_malloc_and_get_section. Free contents on error return. * nlmconv.c (copy_sections): Use bfd_malloc_and_get_section.
Diffstat (limited to 'binutils/objcopy.c')
-rw-r--r--binutils/objcopy.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/binutils/objcopy.c b/binutils/objcopy.c
index 4f48190..23a949d 100644
--- a/binutils/objcopy.c
+++ b/binutils/objcopy.c
@@ -2650,14 +2650,15 @@ copy_object (bfd *ibfd, bfd *obfd, const bfd_arch_info_type *input_arch)
continue;
}
- bfd_byte * contents = xmalloc (size);
- if (bfd_get_section_contents (ibfd, osec, contents, 0, size))
+ bfd_byte *contents;
+ if (bfd_malloc_and_get_section (ibfd, osec, &contents))
{
if (fwrite (contents, 1, size, f) != size)
{
non_fatal (_("error writing section contents to %s (error: %s)"),
pdump->filename,
strerror (errno));
+ free (contents);
return FALSE;
}
}