[filesystem 1.34] bug - basic_path::append()

While investigating basic_path::append (please see my previous posts), I found something a bit suspect. template<class String, class Traits> template <class InputIterator> basic_path<String, Traits> & basic_path<String, Traits>::append( InputIterator first, InputIterator last ) { if ( detail::is_separator<path_type>( *first ) && detail::is_separator<path_type>( *(first+1) ) && *(first+2) == colon<path_type>::value ) first += 3; What if first == last? Worse, what if 'last' is the typical past-the-end (dereferencing undefined) value? Consider the following test-cases: -------------- path_test.cpp.patch -------------------- *** path_test.cpp.orig Fri Jan 13 20:39:08 2006 --- path_test.cpp Fri Jan 13 20:26:19 2006 *************** *** 12,17 **** --- 12,18 ---- #include <iostream> #include <sstream> #include <string> + #include <vector> #include <cstring> #include <cassert> *************** *** 251,256 **** --- 252,269 ---- PATH_CHECK( p5, bf ); p5.append( bf, bf + sizeof(bf) ); PATH_CHECK( p5, "bar/foo/bar/foo" ); + + std::string s1( "//:somestring" ); + std::vector<char> v1( s1.begin(), s1.end() ); + v1.resize( 0 ); + + p5.assign( v1.begin(), v1.end() ); + std::string s2( v1.begin(), v1.end() ); + PATH_CHECK( p5, s2 ); + + p5.assign( s1.begin(), s1.begin() + 1 ); + PATH_CHECK( p5, "/" ); + # endif BOOST_CHECK( p1 != p4 ); ------------- end path_test.cpp.patch -----------------

"David Whetstone" <mr.fixit@mac.com> wrote in message news:dqa00f$73r$1@sea.gmane.org...
While investigating basic_path::append (please see my previous posts), I found something a bit suspect.
template<class String, class Traits> template <class InputIterator> basic_path<String, Traits> & basic_path<String, Traits>::append( InputIterator first, InputIterator last ) { if ( detail::is_separator<path_type>( *first ) && detail::is_separator<path_type>( *(first+1) ) && *(first+2) == colon<path_type>::value ) first += 3;
What if first == last? Worse, what if 'last' is the typical past-the-end (dereferencing undefined) value?
Nice catch! The code was a cut-and-past from the previous function, where the input was zero-terminated, and thus correct in that context but not in the additional context. There was also a more subtle bug. The code was supposed to require only input iterators, yet in fact required random access iterators. If, as seems likely, C++0x gets concept checking then this kind of requirements-failure error will get detected by the compiler.
Consider the following test-cases: ...
I've added these - thanks! It will be a couple of days before the fix appears in CVS - it will be part of a update addressing several other issues raised recently on the list. The code is done and tested on Windows, but needs to be tested on a POSIX system before committing to the CVS HEAD. Thanks for the report, --Beman

Beman Dawes wrote:
I've added these - thanks!
Happy to be of service. Thank you for doing all the heavy lifting.
It will be a couple of days before the fix appears in CVS - it will be part of a update addressing several other issues raised recently on the list.
Looking forward to it. Any chance this will include a version of basic_path::append that will work with its own iterators?
participants (2)
-
Beman Dawes
-
David Whetstone