aboutsummaryrefslogtreecommitdiff
path: root/binutils/objdump.c
diff options
context:
space:
mode:
authorAlan Modra <amodra@gmail.com>2020-03-10 13:22:25 +1030
committerAlan Modra <amodra@gmail.com>2020-03-10 13:54:01 +1030
commit41da082238bbc3bbe8bac1b0fbcab716fe7c87f2 (patch)
tree9d480e5a61bea83f6ae61724f3a81e38ad12b05d /binutils/objdump.c
parent6b5e16ffd3e8886fa3fb90d63e3200fcc373848e (diff)
downloadgdb-41da082238bbc3bbe8bac1b0fbcab716fe7c87f2.zip
gdb-41da082238bbc3bbe8bac1b0fbcab716fe7c87f2.tar.gz
gdb-41da082238bbc3bbe8bac1b0fbcab716fe7c87f2.tar.bz2
objdump disassembly of files without symbols
ubsan complains about memcpy with a NULL src even when size is zero. * objdump.c (disassemble_section): Don't call qsort unless sym count is at least two. (disassemble_data): Don't call memcpy with NULL src.
Diffstat (limited to 'binutils/objdump.c')
-rw-r--r--binutils/objdump.c12
1 files changed, 8 insertions, 4 deletions
diff --git a/binutils/objdump.c b/binutils/objdump.c
index 6eef38f..211be92 100644
--- a/binutils/objdump.c
+++ b/binutils/objdump.c
@@ -3109,7 +3109,8 @@ disassemble_section (bfd *abfd, asection *section, void *inf)
/* Sort the symbols into value and section order. */
compare_section = section;
- qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
+ if (sorted_symcount > 1)
+ qsort (sorted_syms, sorted_symcount, sizeof (asymbol *), compare_symbols);
/* Skip over the relocs belonging to addresses below the
start address. */
@@ -3376,10 +3377,13 @@ disassemble_data (bfd *abfd)
sorted_symcount = symcount ? symcount : dynsymcount;
sorted_syms = (asymbol **) xmalloc ((sorted_symcount + synthcount)
* sizeof (asymbol *));
- memcpy (sorted_syms, symcount ? syms : dynsyms,
- sorted_symcount * sizeof (asymbol *));
+ if (sorted_symcount != 0)
+ {
+ memcpy (sorted_syms, symcount ? syms : dynsyms,
+ sorted_symcount * sizeof (asymbol *));
- sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+ sorted_symcount = remove_useless_symbols (sorted_syms, sorted_symcount);
+ }
for (i = 0; i < synthcount; ++i)
{