From 2372ccc111cd8d33553fb20116a449ba5df5f6e9 Mon Sep 17 00:00:00 2001 From: Reid Spencer Date: Wed, 8 Aug 2007 20:01:58 +0000 Subject: [PATCH] Make getSTDIN return null if the standard input is empty, as the header file documentation implies and as its uses depend. git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@40939 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Support/MemoryBuffer.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp index 43eb1813ad6..0ae5676acce 100644 --- a/lib/Support/MemoryBuffer.cpp +++ b/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;