Boost C++ Libraries: Ticket #4439: Possible infinite loop in boost:: filesystem::copy_file for unix https://svn.boost.org/trac10/ticket/4439 <p> In the write cycle: </p> <blockquote> <p> do { </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> <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/4439 Trac 1.4.3 Marshall Clow Fri, 13 Aug 2010 22:30:58 GMT <link>https://svn.boost.org/trac10/ticket/4439#comment:1 </link> <guid isPermaLink="false">https://svn.boost.org/trac10/ticket/4439#comment:1</guid> <description> <p> This seems like a duplicate of <a class="new ticket" href="https://svn.boost.org/trac10/ticket/4438" title="#4438: Bugs: Possible infinite loop in boost:: filesystem::copy_file for unix (new)">#4438</a> </p> </description> <category>Ticket</category> </item> <item> <dc:creator>Steven Watanabe</dc:creator> <pubDate>Fri, 11 Feb 2011 04:29:56 GMT</pubDate> <title>status changed; resolution set https://svn.boost.org/trac10/ticket/4439#comment:2 https://svn.boost.org/trac10/ticket/4439#comment:2 <ul> <li><strong>status</strong> <span class="trac-field-old">new</span> → <span class="trac-field-new">closed</span> </li> <li><strong>resolution</strong> → <span class="trac-field-new">duplicate</span> </li> </ul> Ticket