aboutsummaryrefslogtreecommitdiff
path: root/lib/Support
diff options
context:
space:
mode:
authorDan Gohman <gohman@apple.com>2010-05-27 17:31:51 +0000
committerDan Gohman <gohman@apple.com>2010-05-27 17:31:51 +0000
commit30377e780918aacda1befa47054c61b0155c194c (patch)
tree0433fbc0a31e3ee419d7b86770778234d391f787 /lib/Support
parent95131fcb671f13b931ea3cbb6bbd3fd735f1c5dc (diff)
Add basic error checking to MemoryBuffer::getSTDIN.
git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@104855 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Support')
-rw-r--r--lib/Support/MemoryBuffer.cpp9
1 files changed, 7 insertions, 2 deletions
diff --git a/lib/Support/MemoryBuffer.cpp b/lib/Support/MemoryBuffer.cpp
index 2b95089b52..ac79518903 100644
--- a/lib/Support/MemoryBuffer.cpp
+++ b/lib/Support/MemoryBuffer.cpp
@@ -137,7 +137,7 @@ MemoryBuffer *MemoryBuffer::getFileOrSTDIN(StringRef Filename,
int64_t FileSize,
struct stat *FileInfo) {
if (Filename == "-")
- return getSTDIN();
+ return getSTDIN(ErrStr);
return getFile(Filename, ErrStr, FileSize, FileInfo);
}
@@ -263,7 +263,7 @@ public:
};
}
-MemoryBuffer *MemoryBuffer::getSTDIN() {
+MemoryBuffer *MemoryBuffer::getSTDIN(std::string *ErrStr) {
char Buffer[4096*4];
std::vector<char> FileData;
@@ -279,6 +279,11 @@ MemoryBuffer *MemoryBuffer::getSTDIN() {
FileData.insert(FileData.end(), Buffer, Buffer+ReadBytes);
} while (ReadBytes == sizeof(Buffer));
+ if (!feof(stdin)) {
+ if (ErrStr) *ErrStr = "error reading from stdin";
+ return 0;
+ }
+
FileData.push_back(0); // &FileData[Size] is invalid. So is &*FileData.end().
size_t Size = FileData.size();
MemoryBuffer *B = new STDINBufferFile();