[llvm-commits] [llvm] r37829 - /llvm/trunk/lib/Support/MemoryBuffer.cpp
Nick Lewycky
nicholas at mxc.ca
Sat Jun 30 20:06:30 PDT 2007
Author: nicholas
Date: Sat Jun 30 22:06:30 2007
New Revision: 37829
URL: http://llvm.org/viewvc/llvm-project?rev=37829&view=rev
Log:
Fix undefined behaviour reported by the new --enable-expensive-checks option.
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=37829&r1=37828&r2=37829&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Sat Jun 30 22:06:30 2007
@@ -251,8 +251,9 @@
while (size_t ReadBytes = fread(Buffer, 1, 4096*4, stdin))
FileData.insert(FileData.end(), Buffer, Buffer+ReadBytes);
+ FileData.push_back(0); // &FileData[Size] is invalid. So is &*FileData.end().
size_t Size = FileData.size();
MemoryBuffer *B = new STDINBufferFile();
- B->initCopyOf(&FileData[0], &FileData[Size]);
+ B->initCopyOf(&FileData[0], &FileData[Size-1]);
return B;
}
More information about the llvm-commits
mailing list