Boost logo

Boost Users :

From: raulh39_at_[hidden]
Date: 2008-01-18 14:46:20


Hi,

I have encountered an error in the filesystem library.
I am working with Boost 1.34.1, SunOs 5.7, and a multi-threaded environment.
This small program reproduces the problem:

------------------------------------------------------
#include <boost/filesystem/fstream.hpp>
#include <boost/filesystem/operations.hpp>
#include <boost/filesystem/convenience.hpp>
#include <boost/foreach.hpp>

#include <iostream>

int main()
{
    namespace fs = boost::filesystem;

    fs::path path(".",fs::native);
    if(fs::exists(path) && fs::is_directory(path))
    {
        fs::directory_iterator begin(path), end;
        BOOST_FOREACH(fs::path file, std::make_pair(begin,end))
            std::cout << file.leaf() << std::endl;
    }
}
------------------------------------------------------

The problem is that this program never ends.

Apparently the "begin" iterator never reaches the "end" iterator.
It only happens in a multi-thread compilation.

But, I think that I know where the bug is.

In the file
libs/filesystem/src/operations.cpp
is were the function 'readdir_r_simulator' is implemented, and, if I understand it correctly, it should return != 0 if an error has ocurred.

But, the 1247 line:
            { return ::readdir_r( dirp, entry, result ); }
is wrong, because when an error is encountered, readdir_r() returns a null pointer.
NULL is converted to the int 0 and the function returns it.

So, I suggest to change that line with:
            { if(::readdir_r( dirp, entry, result )==NULL) return errno; else return 0; }

I will try to post this bug to the bug tracking facility (¿trac?).

Regards,
Raul.


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