Boost logo

Boost Users :

From: Paul Giaccone (paulg_at_[hidden])
Date: 2006-02-06 10:22:21


I am iterating over the subdirectories in a directory. The code I have
for this has always worked up until now, but now it is crashing when I
create the iterator (ask "What did you change?" if you like; the answer
is "If I knew that...").

My question is: what can cause the creation of an iterator to crash?
Looking at the documentation, directory_iterator(my_path) throws if
!exists(my_path), which is fair enough. This check is already in my
code, however, and does not report that the path does not exist.

Here is a (revised) segment of my code:

    const char* source_directory = getenv(MYENVVAR);

    if ((source_directory == NULL) || (source_directory[0] == '\0'))
    {
       return false;
    }

    boost::filesystem::path dir_path(source_directory,
boost::filesystem::native);
    boost::filesystem::directory_iterator end_iterator;

    if (!exists(dir_path))
    {
        return false;
    }

    boost::filesystem::directory_iterator dir_iterator(dir_path); //CRASH

    while (dir_iterator != end_iterator)
    {
       //do whatever I do here
       dir_iterator++;
    }

The program crashes where indicated. The path exists. I've tried
replacing the const char* at the beginning with a std::string (then
using .c_str() where appropriate) but this makes no difference.

So, apart from the path not existing, how else can
directory_iterator(dir_path) cause an error?

Incidental info: This works fine in Windows (albeit with a different
path); this code builds a shared object for use in Shake, meaning I
can't use gdb; I am working with gcc 3.2.3 and Boost 1.33.1.

Paul


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net