diff options
author | Pete Cooper <peter_cooper@apple.com> | 2016-03-22 22:59:35 +0000 |
---|---|---|
committer | Pete Cooper <peter_cooper@apple.com> | 2016-03-22 22:59:35 +0000 |
commit | b9a9d7163f984123875a8c6276a1567fe79bd29f (patch) | |
tree | 478802532cc5ab9572df69725f99e4908d914c25 /lld/lib/ReaderWriter | |
parent | 8e1b9a17a692d428eeb16c0189ccbbaa741b366d (diff) | |
download | bcm5719-llvm-b9a9d7163f984123875a8c6276a1567fe79bd29f.tar.gz bcm5719-llvm-b9a9d7163f984123875a8c6276a1567fe79bd29f.zip |
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
Diffstat (limited to 'lld/lib/ReaderWriter')
-rw-r--r-- | lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp b/lld/lib/ReaderWriter/MachO/ArchHandler_x86.cpp index faabffaf5ca..9e036870b65 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. |