[PATCH] D45789: Fix nullptr passed to memcpy in lld/COFF/Chunks.cpp

Bob Haarman via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 20 14:54:00 PDT 2018


inglorion updated this revision to Diff 143397.
inglorion marked an inline comment as done.
inglorion added a comment.

Fair enough. Changed it to only do the memcpy if the ArrayRef is not
empty, and otherwise leave the function alone.


https://reviews.llvm.org/D45789

Files:
  lld/COFF/Chunks.cpp


Index: lld/COFF/Chunks.cpp
===================================================================
--- lld/COFF/Chunks.cpp
+++ lld/COFF/Chunks.cpp
@@ -271,7 +271,8 @@
     return;
   // Copy section contents from source object file to output file.
   ArrayRef<uint8_t> A = getContents();
-  memcpy(Buf + OutputSectionOff, A.data(), A.size());
+  if (!A.empty())
+    memcpy(Buf + OutputSectionOff, A.data(), A.size());
 
   // Apply relocations.
   size_t InputSize = getSize();


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D45789.143397.patch
Type: text/x-patch
Size: 475 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180420/09950f29/attachment.bin>


More information about the llvm-commits mailing list