From: Chandler Carruth Date: Tue, 4 Aug 2015 01:00:56 +0000 (+0000) Subject: [UB] Fix yet another use of memcpy with a null pointer argument. I think X-Git-Url: http://plrg.eecs.uci.edu/git/?p=oota-llvm.git;a=commitdiff_plain;h=4f2a94439aa72a3ba0b9340f1fe5b1bbff0279c3 [UB] Fix yet another use of memcpy with a null pointer argument. I think this is the last of them in my build of LLVM. Haven't tried Clang yet. Found via UBSan. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@243934 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 98862e96b74..d09ef3a4c0b 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/lib/Support/MemoryBuffer.cpp @@ -57,7 +57,8 @@ void MemoryBuffer::init(const char *BufStart, const char *BufEnd, /// CopyStringRef - Copies contents of a StringRef into a block of memory and /// null-terminates it. static void CopyStringRef(char *Memory, StringRef Data) { - memcpy(Memory, Data.data(), Data.size()); + if (!Data.empty()) + memcpy(Memory, Data.data(), Data.size()); Memory[Data.size()] = 0; // Null terminate string. }