[llvm-commits] [lld] r149430 - /lld/trunk/lib/Core/NativeWriter.cpp

Michael J. Spencer bigcheesegs at gmail.com
Tue Jan 31 13:46:41 PST 2012


Author: mspencer
Date: Tue Jan 31 15:46:41 2012
New Revision: 149430

URL: http://llvm.org/viewvc/llvm-project?rev=149430&view=rev
Log:
&vectorval[0] is UB when vectorval.size() == 0.

Modified:
    lld/trunk/lib/Core/NativeWriter.cpp

Modified: lld/trunk/lib/Core/NativeWriter.cpp
URL: http://llvm.org/viewvc/llvm-project/lld/trunk/lib/Core/NativeWriter.cpp?rev=149430&r1=149429&r2=149430&view=diff
==============================================================================
--- lld/trunk/lib/Core/NativeWriter.cpp (original)
+++ lld/trunk/lib/Core/NativeWriter.cpp Tue Jan 31 15:46:41 2012
@@ -38,12 +38,16 @@
   // write the lld::File in native format to the specified stream
   void write(llvm::raw_ostream& out) {
     out.write((char*)_headerBuffer, _headerBufferSize);
-    out.write((char*)&_definedAtomIvars[0], 
-              _definedAtomIvars.size()*sizeof(NativeDefinedAtomIvarsV1));
-    out.write((char*)&_attributes[0], 
-              _attributes.size()*sizeof(NativeAtomAttributesV1));
-    out.write((char*)&_contentPool[0], _contentPool.size());
-    out.write(&_stringPool[0], _stringPool.size());
+    if (!_definedAtomIvars.empty())
+      out.write((char*)&_definedAtomIvars[0],
+                _definedAtomIvars.size()*sizeof(NativeDefinedAtomIvarsV1));
+    if (!_attributes.empty())
+      out.write((char*)&_attributes[0],
+                _attributes.size()*sizeof(NativeAtomAttributesV1));
+    if (!_contentPool.empty())
+      out.write((char*)&_contentPool[0], _contentPool.size());
+    if (!_stringPool.empty())
+      out.write(&_stringPool[0], _stringPool.size());
   }
 
 private:





More information about the llvm-commits mailing list