Avoid UB when creating empty atoms. NFC.
authorPete Cooper <peter_cooper@apple.com>
Thu, 24 Mar 2016 01:16:06 +0000 (01:16 +0000)
committerPete Cooper <peter_cooper@apple.com>
Thu, 24 Mar 2016 01:16:06 +0000 (01:16 +0000)
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

index aa3b042..96070ba 100644 (file)
@@ -334,6 +334,8 @@ struct MappingTraits<Section> {
       NormalizedFile *file = info->_normalizeMachOFile;
       assert(file != nullptr);
       size_t size = _normalizedContent.size();
+      if (!size)
+        return ArrayRef<uint8_t>();
       uint8_t *bytes = file->ownedAllocations.Allocate<uint8_t>(size);
       std::copy(_normalizedContent.begin(), _normalizedContent.end(), bytes);
       return makeArrayRef(bytes, size);