[llvm-commits] [llvm] r40939 - /llvm/trunk/lib/Support/MemoryBuffer.cpp
Reid Spencer
rspencer at reidspencer.com
Wed Aug 8 13:01:58 PDT 2007
Author: reid
Date: Wed Aug 8 15:01:58 2007
New Revision: 40939
URL: http://llvm.org/viewvc/llvm-project?rev=40939&view=rev
Log:
Make getSTDIN return null if the standard input is empty, as the header file
documentation implies and as its uses depend.
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=40939&r1=40938&r2=40939&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Wed Aug 8 15:01:58 2007
@@ -248,11 +248,13 @@
// Read in all of the data from stdin, we cannot mmap stdin.
sys::Program::ChangeStdinToBinary();
- while (size_t ReadBytes = fread(Buffer, 1, 4096*4, stdin))
+ while (size_t ReadBytes = fread(Buffer, sizeof(char), 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();
+ if (Size <= 1)
+ return 0;
MemoryBuffer *B = new STDINBufferFile();
B->initCopyOf(&FileData[0], &FileData[Size-1]);
return B;
More information about the llvm-commits
mailing list