[Boost-bugs] [Boost C++ Libraries] #11910: recursive_directory_iterator doesn't set end_iterator properly when exception is thrown in increment()

Subject: [Boost-bugs] [Boost C++ Libraries] #11910: recursive_directory_iterator doesn't set end_iterator properly when exception is thrown in increment()
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2016-01-13 16:49:16


#11910: recursive_directory_iterator doesn't set end_iterator properly when
exception is thrown in increment()
----------------------------------------+------------------------
 Reporter: David Raphael <draphael@…> | Owner: bemandawes
     Type: Bugs | Status: new
Milestone: To Be Determined | Component: filesystem
  Version: Boost 1.60.0 | Severity: Problem
 Keywords: |
----------------------------------------+------------------------
 in operations.hpp the increment function looks like this:

 {{{

     void increment()
     {
       BOOST_ASSERT_MSG(m_imp.get(),
         "increment of end recursive_directory_iterator");
       m_imp->increment(0);
       if (m_imp->m_stack.empty())
         m_imp.reset(); // done, so make end iterator
     }

 }}}

 The problem occurs when you are incrementing using the ++ operator. If
 there is an exception, the stack is never checked to see if it is empty
 because the m_imp->increment() throws an exception. This leaves the
 recursive iterator in a bad state.

 I fixed it by doing this:

 {{{

     void increment()
     {
       BOOST_ASSERT_MSG(m_imp.get(),
         "increment of end recursive_directory_iterator");
       try
       {
         m_imp->increment(0);
       }
       catch(filesystem_error e)
       {
         if (m_imp->m_stack.empty())
           m_imp.reset(); // done, so make end iterator
         throw(e);
       }
       if (m_imp->m_stack.empty())
         m_imp.reset(); // done, so make end iterator
     }

 }}}

 but I'm not sure that is the right way to address this issue.

-- 
Ticket URL: <https://svn.boost.org/trac/boost/ticket/11910>
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:19 UTC