Boost C++ Libraries: Ticket #2542: filesystem: wrong close 0 descriptor in copy_file_api on unix https://svn.boost.org/trac10/ticket/2542 <p> This code is wrong if ::stat call fails - it is just close descriptor with number 0 (by if ( infile &gt;= 0 ) ::close( infile );). </p> <blockquote> <p> BOOST_FILESYSTEM_DECL error_code copy_file_api( const std::string &amp; from_file_ph, </p> <blockquote> <p> const std::string &amp; to_file_ph ) </p> </blockquote> <p> { </p> <blockquote> <p> const std::size_t buf_sz = 32768; boost::scoped_array&lt;char&gt; buf( new char [buf_sz] ); int infile=0, outfile=0; <em> init quiets compiler warning struct stat from_stat; </em></p> </blockquote> </blockquote> <blockquote> <blockquote> <p> if ( ::stat( from_file_ph.c_str(), &amp;from_stat ) != 0 </p> <blockquote> <table class="wiki"> <tr><td> (infile = ::open( from_file_ph.c_str(), </td></tr></table> <blockquote> <p> O_RDONLY )) &lt; 0 </p> </blockquote> <table class="wiki"> <tr><td> (outfile = ::open( to_file_ph.c_str(), </td></tr></table> <blockquote> <blockquote> <p> O_WRONLY | O_CREAT | O_EXCL, from_stat.st_mode )) &lt; 0 ) </p> </blockquote> </blockquote> </blockquote> <p> { </p> <blockquote> <p> if ( infile &gt;= 0 ) ::close( infile ); return error_code( errno, system_category ); </p> </blockquote> <p> } </p> </blockquote> </blockquote> <p> Fix is just changing </p> <blockquote> <p> int infile=0, outfile=0; <em> init quiets compiler warning </em></p> </blockquote> <p> to </p> <blockquote> <p> int infile=-1, outfile=-1; </p> </blockquote> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/2542 Trac 1.4.3 ai@… Fri, 28 Nov 2008 06:56:43 GMT attachment set https://svn.boost.org/trac10/ticket/2542 https://svn.boost.org/trac10/ticket/2542 <ul> <li><strong>attachment</strong> → <span class="trac-field-new">operations.patch</span> </li> </ul> Ticket Beman Dawes Sun, 30 Nov 2008 02:49:15 GMT status changed; resolution set https://svn.boost.org/trac10/ticket/2542#comment:1 https://svn.boost.org/trac10/ticket/2542#comment:1 <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">fixed</span> </li> </ul> <p> (In <a class="changeset" href="https://svn.boost.org/trac10/changeset/50033" title="Filesystem: fix #2542, wrong close 0 descriptor in copy_file_api on unix">[50033]</a>) Filesystem: fix <a class="closed ticket" href="https://svn.boost.org/trac10/ticket/2542" title="#2542: Bugs: filesystem: wrong close 0 descriptor in copy_file_api on unix (closed: fixed)">#2542</a>, wrong close 0 descriptor in copy_file_api on unix </p> Ticket