]> git.ipfire.org Git - thirdparty/binutils-gdb.git/commitdiff
objdump disassembly of files without symbols
authorAlan Modra <amodra@gmail.com>
Tue, 10 Mar 2020 02:52:25 +0000 (13:22 +1030)
committerAlan Modra <amodra@gmail.com>
Tue, 10 Mar 2020 03:24:01 +0000 (13:54 +1030)
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.

binutils/ChangeLog
binutils/objdump.c

index 05c29397f8373a954d0be937489a19ddd0c5f211..fc456a2259d82c54ef74586dec8f3efcbe93e60f 100644 (file)
@@ -1,3 +1,9 @@
+2020-03-10  Alan Modra  <amodra@gmail.com>
+
+       * objdump.c (disassemble_section): Don't call qsort unless
+       sym count is at least two.
+       (disassemble_data): Don't call memcpy with NULL src.
+
 2020-03-09  Alan Modra  <amodra@gmail.com>
 
        PR 25645
index 6eef38f0e28c067051e6fda01d021ff4e59cee0e..211be9239f885739a0d4cc188db12e1fa1423e3b 100644 (file)
@@ -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)
     {