From b29ecbd4e9149c474a6ed3fe9fb4c30f3dcbbe66 Mon Sep 17 00:00:00 2001 From: Pete Cooper Date: Thu, 24 Mar 2016 01:16:06 +0000 Subject: [PATCH] Avoid UB when creating empty atoms. NFC. The stack-size.yaml test had an empty atom content array. This is legal, but asking a BumpPtrAllocator for 0 sized data may not be legal. Instead just avoid requesting any data when we can just return an empty ArrayRef instead. llvm-svn: 264234 --- lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp index aa3b042..96070ba 100644 --- a/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp +++ b/lld/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp @@ -334,6 +334,8 @@ struct MappingTraits
{ NormalizedFile *file = info->_normalizeMachOFile; assert(file != nullptr); size_t size = _normalizedContent.size(); + if (!size) + return ArrayRef(); uint8_t *bytes = file->ownedAllocations.Allocate(size); std::copy(_normalizedContent.begin(), _normalizedContent.end(), bytes); return makeArrayRef(bytes, size); -- 2.7.4