Fixed bug in filesystem library ?

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; } } }

Luca Severini wrote:
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
std::string is broken in XCode 3.2.1. According to the collective intelligence of the web, one reason is that its standard library has been built with _GLIBCXX_FULLY_DYNAMIC_STRING defined, whereas the IDE by default doesn't define it, leading to random crashes of the sort you report. Others claim that there is a mismatch in the definitions of _GLIBCXX_DEBUG=1 _GLIBCXX_DEBUG_PEDANTIC=1 in a debug build; yet others report problems with "Symbols Hidden by Default", although this may not be the cause of your problem. In your case, I'd first try the _GLIBCXX_FULLY_DYNAMIC_STRING define. BTW, a std::string is never uninitialized. It's initialized to an empty string by default. http://stackoverflow.com/questions/1603300/xcode-3-2-1-and-c-string-fails http://groups.google.com/group/boost-list/browse_thread/thread/1c5a614a9e8c9...
participants (2)
-
Luca Severini
-
Peter Dimov