Add a sanity check in MemoryBuffer::getOpenFile() to make sure we don't hang
[oota-llvm.git] / lib / Support / MemoryBuffer.cpp
index 4b15587db7ac5bfeb9ebe44a3ceec99172734da3..911a03f8088bd70f97352b36352f254e68c47d2b 100644 (file)
@@ -336,7 +336,11 @@ error_code MemoryBuffer::getOpenFile(int FD, const char *Filename,
       // Error while reading.
       return error_code(errno, posix_category());
     }
-    assert(NumRead != 0 && "fstat reported an invalid file size.");
+    if (NumRead == 0) {
+      assert(0 && "We got inaccurate FileSize value or fstat reported an "
+                   "invalid file size.");
+      break;
+    }
     BytesLeft -= NumRead;
     BufPtr += NumRead;
   }