Avoid ubsan complaint in BFD
authorTom Tromey <tom@tromey.com>
Mon, 16 Jul 2018 00:07:40 +0000 (18:07 -0600)
committerTom Tromey <tom@tromey.com>
Mon, 23 Jul 2018 14:14:00 +0000 (08:14 -0600)
I built gdb with ubsan and ran the test suite.

One complaint was due to bfd_get_elf_phdrs passing NULL to memcpy.
This patch avoids the complaint.

bfd/ChangeLog
2018-07-23  Tom Tromey  <tom@tromey.com>

* elf.c (bfd_get_elf_phdrs): Don't call memcpy with size 0.

bfd/ChangeLog
bfd/elf.c

index 5b79a259951248746d7dd521f6c47ef67e68501a..19fd9df2cb925427067205d7422421ecae9e62f9 100644 (file)
@@ -1,3 +1,7 @@
+2018-07-23  Tom Tromey  <tom@tromey.com>
+
+       * elf.c (bfd_get_elf_phdrs): Don't call memcpy with size 0.
+
 2018-07-21  Eric Botcazou  <ebotcazou@adacore.com>
 
        * elf32-arm.c (elf32_arm_final_link_relocate) <R_ARM_GOT32>: Small
index 874629dc8594ec322e2fee613213fd3081832670..f72182788f9e2c5428fb23b3d951de2502d0f814 100644 (file)
--- a/bfd/elf.c
+++ b/bfd/elf.c
@@ -11629,8 +11629,9 @@ bfd_get_elf_phdrs (bfd *abfd, void *phdrs)
     }
 
   num_phdrs = elf_elfheader (abfd)->e_phnum;
-  memcpy (phdrs, elf_tdata (abfd)->phdr,
-         num_phdrs * sizeof (Elf_Internal_Phdr));
+  if (num_phdrs != 0)
+    memcpy (phdrs, elf_tdata (abfd)->phdr,
+           num_phdrs * sizeof (Elf_Internal_Phdr));
 
   return num_phdrs;
 }
This page took 0.031359 seconds and 4 git commands to generate.