From baf3dd99e22758fbee1d22ec75d2793fe4c5c8c7 Mon Sep 17 00:00:00 2001 From: Pavol Droba Date: Mon, 18 Aug 2008 18:32:51 +0000 Subject: [PATCH] fox for allocation bug in is_any_ofF [SVN r48198] --- .../string/detail/classification.hpp | 48 ++++++++++++------- 1 file changed, 30 insertions(+), 18 deletions(-) diff --git a/include/boost/algorithm/string/detail/classification.hpp b/include/boost/algorithm/string/detail/classification.hpp index 2fa3b6d..71e0f3b 100644 --- a/include/boost/algorithm/string/detail/classification.hpp +++ b/include/boost/algorithm/string/detail/classification.hpp @@ -28,11 +28,7 @@ namespace boost { // classification functors -----------------------------------------------// -#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) -#pragma warning(push) -#pragma warning(disable:4512) //assignment operator could not be generated -#endif - // is_classified functor + // is_classified functor struct is_classifiedF : public predicate_facade { @@ -42,7 +38,6 @@ namespace boost { // Constructor from a locale is_classifiedF(std::ctype_base::mask Type, std::locale const & Loc = std::locale()) : m_Type(Type), m_Locale(Loc) {} - // Operation template bool operator()( CharT Ch ) const @@ -59,13 +54,10 @@ namespace boost { #endif private: - const std::ctype_base::mask m_Type; - const std::locale m_Locale; + std::ctype_base::mask m_Type; + std::locale m_Locale; }; -#if BOOST_WORKAROUND(BOOST_MSVC, >= 1400) -#pragma warning(pop) -#endif // is_any_of functor /* @@ -144,31 +136,51 @@ namespace boost { { if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0) { - delete m_Storage.m_dynSet; + delete [] m_Storage.m_dynSet; } } // Assignment is_any_ofF& operator=(const is_any_ofF& Other) { - // Prepare storage - m_Storage.m_dynSet=0; - m_Size=Other.m_Size; + // Prepare storage const set_value_type* SrcStorage=0; set_value_type* DestStorage=0; - if(m_Size<=FIXED_STORAGE_SIZE) + if(Other.m_Size<=FIXED_STORAGE_SIZE) { // Use fixed storage DestStorage=&m_Storage.m_fixSet[0]; SrcStorage=&Other.m_Storage.m_fixSet[0]; + + // Delete old storage if was present + if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0) + { + delete [] m_Storage.m_dynSet; + } + + // Set new size + m_Size=Other.m_Size; } else { // Use dynamic storage - m_Storage.m_dynSet=new set_value_type[m_Size]; - DestStorage=m_Storage.m_dynSet; + + // Create new buffer + set_value_type* pTemp=new set_value_type[Other.m_Size]; + DestStorage=pTemp; SrcStorage=Other.m_Storage.m_dynSet; + + // Delete old storage if necessary + if(m_Size>FIXED_STORAGE_SIZE && m_Storage.m_dynSet!=0) + { + delete [] m_Storage.m_dynSet; + } + + // Store the new storage + m_Storage.m_dynSet=pTemp; + // Set new size + m_Size=Other.m_Size; } // Use fixed storage