From b9a9d7163f984123875a8c6276a1567fe79bd29f Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Tue, 22 Mar 2016 22:59:35 +0000 Subject: [PATCH] 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. llvm-svn: 264115 --- lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp index faabffaf5ca8..9e036870b658 100644 --- a/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp +++ b/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp @@ -420,6 +420,11 @@ void ArchHandler_x86::generateAtomContent(const DefinedAtom &atom, 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.