Boost C++ Libraries: Ticket #4438: Possible infinite loop in boost:: filesystem::copy_file for unix https://svn.boost.org/trac10/ticket/4438 <p> In the write cycle: </p> <blockquote> <p> do </p> <blockquote> <p> { </p> <blockquote> <p> if ((sz = ::write(outfile, buf.get() + sz_write, </p> <blockquote> <p> sz_read - sz_write))&lt; 0) </p> </blockquote> <p> { </p> <blockquote> <p> sz_read = sz; <em> cause read loop termination break; </em> and error to be thrown after closes </p> </blockquote> <p> } sz_write += sz; </p> </blockquote> <p> } while (sz_write &lt; sz_read); </p> </blockquote> </blockquote> <p> </p> <p> Always try to write a number of bytes strictly greater than zero and the api ::write returns according to the official documentation :" On success, the number of bytes written is returned (Zero Indicates Nothing Was Written). On error, -1 is returned, and errno is set appropriately". Now imagine that the ::write api for any error or side effect, always returns zero, then we are in an infinite loop. </p> <p> To fix it I think the appropriate condition should be: </p> <dl class="wiki"><dt>if ((sz =</dt><dd>write (outfile, buf.get () + sz_write, sz_read - sz_write)) &lt;= 0) </dd></dl> <p> that is, change the Boolean operation for less than or equal to (&lt;=) </p> <p> If I'm wrong please let me know what to learn. In my opinion you are the best. </p> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/4438 Trac 1.4.3 isundill@… Sun, 23 Feb 2014 09:06:35 GMT <link>https://svn.boost.org/trac10/ticket/4438#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4438#comment:1</guid> <description> <p> I think your error is in your while condition. After an error, your sz_read equal -1, and your sz_write value equal the total number of bits written (minus one). So the condition (X -1 &lt; -1) may be always true. </p> </description> <category>Ticket</category> </item> </channel> </rss>