From 22954dbb7e9a8db1225c2ef891ee4905c22e0e00 Mon Sep 17 00:00:00 2001 From: Dan Gohman Date: Tue, 19 Feb 2013 18:57:53 +0000 Subject: [PATCH] Don't trust st_size of a character device. This fixes using /dev/stdin as an input when stdin is connected to a tty, for example. No test, because it's difficult to write a reasonably portable test for this. /dev/stdin isn't a character device when stdin is redirected from a file or connected to a pipe. llvm-svn: 175542 --- llvm/lib/Support/MemoryBuffer.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/llvm/lib/Support/MemoryBuffer.cpp b/llvm/lib/Support/MemoryBuffer.cpp index 65b4332..b0a2085 100644 --- a/llvm/lib/Support/MemoryBuffer.cpp +++ b/llvm/lib/Support/MemoryBuffer.cpp @@ -322,9 +322,9 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename, return error_code(errno, posix_category()); } - // If this is a named pipe, we can't trust the size. Create the memory - // buffer by copying off the stream. - if (S_ISFIFO(FileInfo.st_mode)) { + // If this is a named pipe or character device, we can't trust the size. + // Create the memory buffer by copying off the stream. + if (S_ISFIFO(FileInfo.st_mode) || S_ISCHR(FileInfo.st_mode)) { return getMemoryBufferForStream(FD, Filename, result); } -- 2.7.4