Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r64928 - in trunk: boost/detail boost/filesystem/v3 libs/filesystem/v3/test
From: bdawes_at_[hidden]
Date: 2010-08-19 13:03:41


Author: bemandawes
Date: 2010-08-19 13:03:38 EDT (Thu, 19 Aug 2010)
New Revision: 64928
URL: http://svn.boost.org/trac/boost/changeset/64928

Log:
Remove path array optimization; problematic when array contains a string shorter than the array length. Reported by Adam Badura.
Text files modified:
   trunk/boost/detail/lightweight_test.hpp | 22 ++++++++++++++++++++++
   trunk/boost/filesystem/v3/path_traits.hpp | 9 ++-------
   trunk/libs/filesystem/v3/test/path_unit_test.cpp | 14 ++++++++++++++
   3 files changed, 38 insertions(+), 7 deletions(-)

Modified: trunk/boost/detail/lightweight_test.hpp
==============================================================================
--- trunk/boost/detail/lightweight_test.hpp (original)
+++ trunk/boost/detail/lightweight_test.hpp 2010-08-19 13:03:38 EDT (Thu, 19 Aug 2010)
@@ -24,6 +24,7 @@
 //
 
 #include <boost/current_function.hpp>
+#include <boost/assert.hpp>
 #include <iostream>
 
 namespace boost
@@ -64,10 +65,31 @@
     }
 }
 
+struct report_errors_reminder
+{
+ bool remembered_to_call_report_errors_function;
+ report_errors_reminder() : remembered_to_call_report_errors_function(false) {}
+ ~report_errors_reminder()
+ {
+ BOOST_ASSERT(remembered_to_call_report_errors_function);
+ }
+};
+
 } // namespace detail
 
+} // namespace boost
+namespace
+{
+ boost::detail::report_errors_reminder boost_report_errors_reminder;
+}
+
+namespace boost
+{
+
 inline int report_errors()
 {
+ boost_report_errors_reminder.remembered_to_call_report_errors_function = true;
+
     int errors = detail::test_errors();
 
     if( errors == 0 )

Modified: trunk/boost/filesystem/v3/path_traits.hpp
==============================================================================
--- trunk/boost/filesystem/v3/path_traits.hpp (original)
+++ trunk/boost/filesystem/v3/path_traits.hpp 2010-08-19 13:03:38 EDT (Thu, 19 Aug 2010)
@@ -196,13 +196,8 @@
     convert(c_str, to, cvt);
   }
   
- // C-style array
- template <typename T, size_t N, class U> inline
- void dispatch(T (&array)[N], U& to, const codecvt_type& cvt) // T, N, U deduced
- {
-// std::cout << "dispatch() array, N=" << N << "\n";
- convert(array, array + N - 1, to, cvt);
- }
+ // Note: there is no dispatch on C-style arrays because the array may
+ // contain a string smaller than the array size.
 
   BOOST_FILESYSTEM_DECL
   void dispatch(const directory_entry & de,

Modified: trunk/libs/filesystem/v3/test/path_unit_test.cpp
==============================================================================
--- trunk/libs/filesystem/v3/test/path_unit_test.cpp (original)
+++ trunk/libs/filesystem/v3/test/path_unit_test.cpp 2010-08-19 13:03:38 EDT (Thu, 19 Aug 2010)
@@ -46,6 +46,8 @@
 #include <iomanip>
 #include <sstream>
 #include <string>
+#include <cstring>
+#include <cwchar>
 #include <locale>
 #include <list>
 
@@ -191,6 +193,18 @@
     PATH_IS(x7, L"array wchar_t");
     BOOST_TEST_EQ(x7.native().size(), 13U);
 
+ char char_array[100];
+ std::strcpy(char_array, "big array char");
+ path x6o(char_array); // array char, only partially full
+ PATH_IS(x6o, L"big array char");
+ BOOST_TEST_EQ(x6o.native().size(), 14U);
+
+ wchar_t wchar_array[100];
+ std::wcscpy(wchar_array, L"big array wchar_t");
+ path x7o(wchar_array); // array char, only partially full
+ PATH_IS(x7o, L"big array wchar_t");
+ BOOST_TEST_EQ(x7o.native().size(), 17U);
+
     path x8(s.c_str()); // const char* null terminated
     PATH_IS(x8, L"string");
     BOOST_TEST_EQ(x8.native().size(), 6U);


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk