[llvm] r243934 - [UB] Fix yet another use of memcpy with a null pointer argument. I think

Chandler Carruth chandlerc at gmail.com
Mon Aug 3 18:00:57 PDT 2015


Author: chandlerc
Date: Mon Aug  3 20:00:56 2015
New Revision: 243934

URL: http://llvm.org/viewvc/llvm-project?rev=243934&view=rev
Log:
[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.

Modified:
    llvm/trunk/lib/Support/MemoryBuffer.cpp

Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=243934&r1=243933&r2=243934&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Mon Aug  3 20:00:56 2015
@@ -57,7 +57,8 @@ void MemoryBuffer::init(const char *BufS
 /// 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.
 }
 





More information about the llvm-commits mailing list