Fix memory corruption problem
authorChris Lattner <sabre@nondot.org>
Tue, 6 May 2003 18:45:02 +0000 (18:45 +0000)
committerChris Lattner <sabre@nondot.org>
Tue, 6 May 2003 18:45:02 +0000 (18:45 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@6003 91177308-0d34-0410-b5e6-96231b3b80d8

include/llvm/Bytecode/Primitives.h

index 31399a0658032a25ab2ed4119c7835619bb703bc..b72bbf29677da895b6c59e49b413755ffd7bee52 100644 (file)
@@ -163,7 +163,8 @@ static inline void output(unsigned i, std::deque<unsigned char> &Out,
   if (pos == -1) 
     Out.insert(Out.end(), (unsigned char*)&i, (unsigned char*)&i+4);
   else
-    *(unsigned*)&Out[pos] = i;
+    // This cannot use block copy because deques are not guaranteed contiguous!
+    std::copy((unsigned char*)&i, 4+(unsigned char*)&i, Out.begin()+pos);
 #else
   if (pos == -1) { // Be endian clean, little endian is our friend
     Out.push_back((unsigned char)i);