[PATCH] D48948: Fix raw_fd_ostream::write_impl hang due to an infinite loop with large output

Owen Reynolds via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Wed Jul 11 08:56:09 PDT 2018


gbreynoo updated this revision to Diff 155017.

https://reviews.llvm.org/D48948

Files:
  lib/Support/raw_ostream.cpp


Index: lib/Support/raw_ostream.cpp
===================================================================
--- lib/Support/raw_ostream.cpp
+++ lib/Support/raw_ostream.cpp
@@ -613,10 +613,17 @@
   assert(FD >= 0 && "File already closed.");
   pos += Size;
 
+#ifdef _WIN64
+  // Windows _write() requires unsigned 32 bit input for 'count',
+  // however to follow POSIX a value above unsigned max should not be used.
+  // Win64 size_t is 64 bit so int 32 max is used below.
+  size_t MaxWriteSize = _I32_MAX;
+#else
   // The maximum write size is limited to SSIZE_MAX because a write
   // greater than SSIZE_MAX is implementation-defined in POSIX.
   // Since SSIZE_MAX is not portable, we use SIZE_MAX >> 1 instead.
   size_t MaxWriteSize = SIZE_MAX >> 1;
+#endif
 
 #if defined(__linux__)
   // It is observed that Linux returns EINVAL for a very large write (>2G).


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D48948.155017.patch
Type: text/x-patch
Size: 883 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180711/2760a39f/attachment.bin>


More information about the llvm-commits mailing list