From b01bfdfda64b684965cd7f97e99e4b0bce5d67fa Mon Sep 17 00:00:00 2001 From: Vitaly Buka Date: Mon, 14 Jun 2021 21:15:54 -0700 Subject: [PATCH] [lld][MachO] Fix UB after D103006 ubsan detected: lld/MachO/SyntheticSections.cpp:636:15: runtime error: null pointer passed as argument 2, which is declared to never be null --- lld/MachO/SyntheticSections.cpp | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lld/MachO/SyntheticSections.cpp b/lld/MachO/SyntheticSections.cpp index 458bbaa289f4..ef84a9d7c0e8 100644 --- a/lld/MachO/SyntheticSections.cpp +++ b/lld/MachO/SyntheticSections.cpp @@ -633,7 +633,8 @@ void DataInCodeSection::finalizeContents() { } void DataInCodeSection::writeTo(uint8_t *buf) const { - memcpy(buf, entries.data(), getRawSize()); + if (!entries.empty()) + memcpy(buf, entries.data(), getRawSize()); } FunctionStartsSection::FunctionStartsSection()