[lld] ac9dd24 - [lld-macho] Try to make ubsan happy

Jez Ng via llvm-commits llvm-commits at lists.llvm.org
Mon Feb 8 11:51:54 PST 2021


Author: Jez Ng
Date: 2021-02-08T14:51:36-05:00
New Revision: ac9dd247da5a54119851cd766e4e9aa3a2be8a19

URL: https://github.com/llvm/llvm-project/commit/ac9dd247da5a54119851cd766e4e9aa3a2be8a19
DIFF: https://github.com/llvm/llvm-project/commit/ac9dd247da5a54119851cd766e4e9aa3a2be8a19.diff

LOG: [lld-macho] Try to make ubsan happy

Summary: We should avoid passing a null pointer to memcpy.

Added: 
    

Modified: 
    lld/MachO/UnwindInfoSection.cpp

Removed: 
    


################################################################################
diff  --git a/lld/MachO/UnwindInfoSection.cpp b/lld/MachO/UnwindInfoSection.cpp
index 73fb50573ce7..507cca0fb601 100644
--- a/lld/MachO/UnwindInfoSection.cpp
+++ b/lld/MachO/UnwindInfoSection.cpp
@@ -415,7 +415,8 @@ void UnwindInfoSection::writeTo(uint8_t *buf) const {
   // LSDAs
   size_t lsdaBytes =
       lsdaEntries.size() * sizeof(unwind_info_section_header_lsda_index_entry);
-  memcpy(iep, lsdaEntries.data(), lsdaBytes);
+  if (lsdaBytes > 0)
+    memcpy(iep, lsdaEntries.data(), lsdaBytes);
 
   // Level-2 pages
   auto *pp = reinterpret_cast<uint32_t *>(reinterpret_cast<uint8_t *>(iep) +


        


More information about the llvm-commits mailing list