Don't trust st_size of a character device. This fixes using
authorDan Gohman <dan433584@gmail.com>
Tue, 19 Feb 2013 18:57:53 +0000 (18:57 +0000)
committerDan Gohman <dan433584@gmail.com>
Tue, 19 Feb 2013 18:57:53 +0000 (18:57 +0000)
/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.

git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@175542 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Support/MemoryBuffer.cpp

index 65b43322e66fe32a9d586ea5701111e608f74a82..b0a20853b5c19d56fbadbb112d481ecc90cbc40f 100644 (file)
@@ -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);
       }