[llvm] r175542 - Don't trust st_size of a character device. This fixes using

Dan Gohman dan433584 at gmail.com
Tue Feb 19 10:57:53 PST 2013


Author: djg
Date: Tue Feb 19 12:57:53 2013
New Revision: 175542

URL: http://llvm.org/viewvc/llvm-project?rev=175542&view=rev
Log:
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.

Modified:
    llvm/trunk/lib/Support/MemoryBuffer.cpp

Modified: llvm/trunk/lib/Support/MemoryBuffer.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Support/MemoryBuffer.cpp?rev=175542&r1=175541&r2=175542&view=diff
==============================================================================
--- llvm/trunk/lib/Support/MemoryBuffer.cpp (original)
+++ llvm/trunk/lib/Support/MemoryBuffer.cpp Tue Feb 19 12:57:53 2013
@@ -322,9 +322,9 @@ error_code MemoryBuffer::getOpenFile(int
         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);
       }
 





More information about the llvm-commits mailing list