[Boost-bugs] [Boost C++ Libraries] #4438: Possible infinite loop in boost:: filesystem::copy_file for unix

Subject: [Boost-bugs] [Boost C++ Libraries] #4438: Possible infinite loop in boost:: filesystem::copy_file for unix
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2010-07-15 12:52:15


#4438: Possible infinite loop in boost:: filesystem::copy_file for unix
--------------------------------------------------------------+-------------
 Reporter: Roberto Carlos Toledano Gómez <rctg82@…> | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: Boost 1.44.0 | Component: filesystem
  Version: Boost Development Trunk | Severity: Problem
 Keywords: |
--------------------------------------------------------------+-------------
 In the write cycle:


      do
       {
         if ((sz = ::write(outfile, buf.get() + sz_write,
           sz_read - sz_write))< 0)
         {
           sz_read = sz; // cause read loop termination
           break; // and error to be thrown after closes
         }
         sz_write += sz;
       } while (sz_write < sz_read);




 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.

 To fix it I think the appropriate condition should be:

  if ((sz =:: write (outfile, buf.get () + sz_write,
           sz_read - sz_write)) <= 0)

 that is, change the Boolean operation for less than or equal to (<=)

 If I'm wrong please let me know what to learn. In my opinion you are the
 best.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/4438>
Boost C++ Libraries <http://www.boost.org/>
Boost provides free peer-reviewed portable C++ source libraries.

This archive was generated by hypermail 2.1.7 : 2017-02-16 18:50:03 UTC