<div dir="ltr">Should probably pull this into the release as it fixes something that could miscompile in the future with a new host compiler.<br><br><div class="gmail_quote"><div dir="ltr">On Mon, Aug 3, 2015 at 6:05 PM Chandler Carruth <<a href="mailto:chandlerc@gmail.com">chandlerc@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: chandlerc<br>
Date: Mon Aug  3 20:00:56 2015<br>
New Revision: 243934<br>
<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject-3Frev-3D243934-26view-3Drev&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=QLOQ0jClplVnBJ8maRgrtUFK_5VxfbGLuz0kQknwa6w&s=gTO1rUpWvs4Lk4FZQuF_y1A_zNH2aOzF5Vn4VmI2G9I&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project?rev=243934&view=rev</a><br>
Log:<br>
[UB] Fix yet another use of memcpy with a null pointer argument. I think<br>
this is the last of them in my build of LLVM. Haven't tried Clang yet.<br>
<br>
Found via UBSan.<br>
<br>
Modified:<br>
    llvm/trunk/lib/Support/MemoryBuffer.cpp<br>
<br>
Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp<br>
URL: <a href="https://urldefense.proofpoint.com/v2/url?u=http-3A__llvm.org_viewvc_llvm-2Dproject_llvm_trunk_lib_Support_MemoryBuffer.cpp-3Frev-3D243934-26r1-3D243933-26r2-3D243934-26view-3Ddiff&d=AwMFaQ&c=8hUWFZcy2Z-Za5rBPlktOQ&r=mQ4LZ2PUj9hpadE3cDHZnIdEwhEBrbAstXeMaFoB9tg&m=QLOQ0jClplVnBJ8maRgrtUFK_5VxfbGLuz0kQknwa6w&s=WYjbRPLFynB-ztnbP8ew5zy36ErCxrsIUxHW8V4Pxtg&e=" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=243934&r1=243933&r2=243934&view=diff</a><br>
==============================================================================<br>
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)<br>
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Mon Aug  3 20:00:56 2015<br>
@@ -57,7 +57,8 @@ void MemoryBuffer::init(const char *BufS<br>
 /// CopyStringRef - Copies contents of a StringRef into a block of memory and<br>
 /// null-terminates it.<br>
 static void CopyStringRef(char *Memory, StringRef Data) {<br>
-  memcpy(Memory, Data.data(), Data.size());<br>
+  if (!Data.empty())<br>
+    memcpy(Memory, Data.data(), Data.size());<br>
   Memory[Data.size()] = 0; // Null terminate string.<br>
 }<br>
<br>
<br>
<br>
_______________________________________________<br>
llvm-commits mailing list<br>
<a href="mailto:llvm-commits@cs.uiuc.edu" target="_blank">llvm-commits@cs.uiuc.edu</a><br>
<a href="http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits" rel="noreferrer" target="_blank">http://lists.cs.uiuc.edu/mailman/listinfo/llvm-commits</a><br>
</blockquote></div></div>