[lld] r264234 - Avoid UB when creating empty atoms. NFC.
David Blaikie via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 24 09:58:36 PDT 2016
On Wed, Mar 23, 2016 at 6:16 PM, Pete Cooper via llvm-commits <
llvm-commits at lists.llvm.org> wrote:
> Author: pete
> Date: Wed Mar 23 20:16:06 2016
> New Revision: 264234
>
> URL: http://llvm.org/viewvc/llvm-project?rev=264234&view=rev
> Log:
> 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.
>
> Modified:
> lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
>
> Modified: lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp
> URL:
> http://llvm.org/viewvc/llvm-project/lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp?rev=264234&r1=264233&r2=264234&view=diff
>
> ==============================================================================
> --- lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp (original)
> +++ lld/trunk/lib/ReaderWriter/MachO/MachONormalizedFileYAML.cpp Wed Mar
> 23 20:16:06 2016
> @@ -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>();
>
You can write this as "return None;" or "return {};" if you like.
> uint8_t *bytes = file->ownedAllocations.Allocate<uint8_t>(size);
> std::copy(_normalizedContent.begin(), _normalizedContent.end(),
> bytes);
> return makeArrayRef(bytes, size);
>
>
> _______________________________________________
> llvm-commits mailing list
> llvm-commits at lists.llvm.org
> http://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-commits
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20160324/f072af25/attachment.html>
More information about the llvm-commits
mailing list