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
This commit is contained in:
Pete Cooper 2016-03-22 22:59:35 +00:00
parent 8e1b9a17a6
commit b9a9d7163f
1 changed files with 5 additions and 0 deletions

View File

@ -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.