summaryrefslogtreecommitdiffstats
path: root/llvm/lib
diff options
context:
space:
mode:
authorReid Spencer <rspencer@reidspencer.com>2007-08-08 20:01:58 +0000
committerReid Spencer <rspencer@reidspencer.com>2007-08-08 20:01:58 +0000
commit155533cf73c74c859d0523cc91c6fffd465b5447 (patch)
tree27e7dd2492a1a988b4455406aa8790622a6e03a4 /llvm/lib
parent8609c069565195dc3c7a324097942d1f36d13750 (diff)
downloadbcm5719-llvm-155533cf73c74c859d0523cc91c6fffd465b5447.tar.gz
bcm5719-llvm-155533cf73c74c859d0523cc91c6fffd465b5447.zip
Make getSTDIN return null if the standard input is empty, as the header file
documentation implies and as its uses depend. llvm-svn: 40939
Diffstat (limited to 'llvm/lib')
-rw-r--r--llvm/lib/Support/MemoryBuffer.cpp6
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp
index 43eb1813ad6..0ae5676acce 100644
--- a/llvm/lib/Support/MemoryBuffer.cpp
+++ b/llvm/lib/Support/MemoryBuffer.cpp
@@ -248,11 +248,13 @@ MemoryBuffer *MemoryBuffer::getSTDIN() {
// 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;
OpenPOWER on IntegriCloud