[lld] r264115 - Avoid memcpy from nullptr. NFC.

Pete Cooper via llvm-commits llvm-commits at lists.llvm.org
Tue Mar 22 15:59:35 PDT 2016


Author: pete
Date: Tue Mar 22 17:59:35 2016
New Revision: 264115

URL: http://llvm.org/viewvc/llvm-project?rev=264115&view=rev
Log:
Avoid memcpy from nullptr.  NFC.

This was caught by the UBSan bot.  When the atom has no size, we would
issue a memcpy with size0 and a nullptr for the source.

Also, this code should never have references inside an empty atom so
add an assert for that while we're here.

Modified:
    lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp

Modified: lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp?rev=264115&r1=264114&r2=264115&view=diff
==============================================================================
--- lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp (original)
+++ lld/trunk/lib/ReaderWriter/MachO/ArchHandler_x86.cpp Tue Mar 22 17:59:35 2016
@@ -420,6 +420,11 @@ void ArchHandler_x86::generateAtomConten
                                           FindAddressForAtom findSectionAddress,
                                           uint64_t imageBaseAddress,
                                           uint8_t *atomContentBuffer) {
+  if (!atom.size()) {
+    assert(atom.begin() == atom.end() &&
+           "Cannot have references without content");
+    return;
+  }
   // Copy raw bytes.
   memcpy(atomContentBuffer, atom.rawContent().data(), atom.size());
   // Apply fix-ups.




More information about the llvm-commits mailing list