|
Boost : |
Subject: [boost] Fixed bug in filesystem library ?
From: Luca Severini (lucaseverini_at_[hidden])
Date: 2009-12-05 05:24:23
Hello everyone,
I'm a newbie to boost libraries but I have some good experience in software development on Mac OS.
Today I use downloaded and used boost for the first time. I use a MacBook Pro with Snow Leopard 10.6.2. The IDE is Xcode 3.2.1
Writing some very basic code to learn how to use the filesystem library I got assertions (below) simply iterating recursilvely through a local directory to list its content.
/Developer/Test/TestFolder
Boost_Test(57690) malloc: *** error for object 0xe518: pointer being freed was not allocated
*** set a breakpoint in malloc_error_break to debug
Investigating in the code I've found the assertions were triggered by two uninitialized std::string variables with same name passed to the functions detail::dir_itr_first() and detail::dir_itr_increment().
Initializing both to the simple content ".", directly in the constructor, seems to have fixed the problem (no assertions anymore).
Here are the two functions I've changed in the file operations.hpp. The code I added is in green. Nothing has been deleted.
I was thinking to follow the instructions to submit the fix but, please excuse me, I've found easier to send an email to the list. Hopefully someone with better knowledge of boost than me will submit gthe fix if it's the case o will find a better solution.
Best regards,
Luac Severini
template<class Path> system::error_code basic_directory_iterator<Path>::m_init(const Path & dir_path)
{
if ( dir_path.empty() )
{
m_imp.reset();
return detail::not_found_error();
}
typename Path::external_string_type name("."); // String initialized to avoid assertion
file_status fs, symlink_fs;
system::error_code ec( detail::dir_itr_first( m_imp->m_handle,
#if defined(BOOST_POSIX_API)
m_imp->m_buffer,
#endif
dir_path.external_directory_string(),
name, fs, symlink_fs ) );
if ( ec )
{
m_imp.reset();
return ec;
}
if ( m_imp->m_handle == 0 ) m_imp.reset(); // eof, so make end iterator
else // not eof
{
m_imp->m_directory_entry.assign( dir_path
/ Path::traits_type::to_internal( name ), fs, symlink_fs );
if ( name[0] == dot<Path>::value // dot or dot-dot
&& (name.size() == 1
|| (name[1] == dot<Path>::value
&& name.size() == 2)) )
{ increment(); }
}
return boost::system::error_code();
}
template<class Path> void basic_directory_iterator<Path>::increment()
{
BOOST_ASSERT( m_imp.get() && "attempt to increment end iterator" );
BOOST_ASSERT( m_imp->m_handle != 0 && "internal program error" );
typename Path::external_string_type name("."); // String initialized to avoid assertion
file_status fs, symlink_fs;
system::error_code ec;
for (;;)
{
ec = detail::dir_itr_increment( m_imp->m_handle,
#if defined(BOOST_POSIX_API)
m_imp->m_buffer,
#endif
name, fs, symlink_fs );
if ( ec )
{
boost::throw_exception( basic_filesystem_error<Path>(
"boost::filesystem::basic_directory_iterator increment",
m_imp->m_directory_entry.path().parent_path(), ec ) );
}
if ( m_imp->m_handle == 0 ) { m_imp.reset(); return; } // eof, make end
if ( !(name[0] == dot<Path>::value // !(dot or dot-dot)
&& (name.size() == 1
|| (name[1] == dot<Path>::value
&& name.size() == 2))) )
{
m_imp->m_directory_entry.replace_filename(
Path::traits_type::to_internal( name ), fs, symlink_fs );
return;
}
}
}
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk